[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays=<n> for stricter handling of flexible arrays

Stephan Bergmann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 4 00:58:00 PDT 2022


sberg added a comment.

I'm surprised that

  $ cat test.c
  struct S {
      int m1;
      int m2[1];
  };
  void f(struct S * s) {
      s->m2[1] = 0;
  }
  
  $ clang -fsyntax-only -fstrict-flex-arrays=1 test.c
  test.c:6:5: warning: array index 1 is past the end of the array (which contains 1 element) [-Warray-bounds]
      s->m2[1] = 0;
      ^     ~
  test.c:3:5: note: array 'm2' declared here
      int m2[1];
      ^
  1 warning generated.

causes a warning?  I would have expected it to be suppressed in this case, as with the lax `-fstrict-flex-arrays=0` default, and only to hit with the stricter `-fstrict-flex-arrays=2`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126864/new/

https://reviews.llvm.org/D126864



More information about the cfe-commits mailing list