array-bounds-ptr-arith.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // RUN: %clang_cc1 -verify -Warray-bounds-pointer-arithmetic %s
  2. // Test case from PR10615
  3. struct ext2_super_block{
  4. unsigned char s_uuid[8]; // expected-note {{declared here}}
  5. };
  6. void* ext2_statfs (struct ext2_super_block *es,int a)
  7. {
  8. return (void *)es->s_uuid + sizeof(int); // no-warning
  9. }
  10. void* broken (struct ext2_super_block *es,int a)
  11. {
  12. return (void *)es->s_uuid + 80; // expected-warning {{refers past the end of the array}}
  13. }
  14. // Test case reduced from PR11594
  15. struct S { int n; };
  16. void pr11594(struct S *s) {
  17. int a[10];
  18. int *p = a - s->n;
  19. }
  20. // Test case reduced from <rdar://problem/11387038>. This resulted in
  21. // an assertion failure because of the typedef instead of an explicit
  22. // constant array type.
  23. struct RDar11387038 {};
  24. typedef struct RDar11387038 RDar11387038Array[1];
  25. struct RDar11387038_Table {
  26. RDar11387038Array z;
  27. };
  28. typedef struct RDar11387038_Table * TPtr;
  29. typedef TPtr *TabHandle;
  30. struct RDar11387038_B { TabHandle x; };
  31. typedef struct RDar11387038_B RDar11387038_B;
  32. void radar11387038() {
  33. RDar11387038_B *pRDar11387038_B;
  34. struct RDar11387038* y = &(*pRDar11387038_B->x)->z[4];
  35. }