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

Kees Cook via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 7 11:41:59 PDT 2022


kees added a comment.

Thanks for working on this!

Doing test builds with the Linux kernel correctly detects a number of trailing arrays that were being treated as flexible arrays (and need to be fixed in the kernel). This is exactly what was expected and wanted. :)



================
Comment at: clang/include/clang/Basic/LangOptions.def:425
 LANGOPT(MatrixTypes, 1, 0, "Enable or disable the builtin matrix type")
+LANGOPT(StrictFlexArrays, 1, 0, "Rely on strict definition of flexible arrays")
 
----------------
I think this option should likely also affect the logic in `-fsanitize=bounds` too, though I think that could be a separate change. Fixing `__bos` is more important. :)


================
Comment at: clang/test/CodeGen/object-size-flex-array.c:27
+  float f;
+  double c[2];
+} foo2_t;
----------------
Perhaps add some additional tests for "not a trailing array" here too, just for completeness?


```
typedef struct {
  double c[0];
  float f;
} fooM0_t;

typedef struct {
  double c[1];
  float f;
} fooM1_t;

typedef struct {
  double c[2];
  float f;
} fooM2_t;

```


================
Comment at: clang/test/CodeGen/object-size-flex-array.c:34
+  // CHECK: ret i32 %
+  // CHECK-STRICT: ret i32 %
+  return OBJECT_SIZE_BUILTIN(f->c, 1);
----------------
Shouldn't this explicitly return -1?


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

https://reviews.llvm.org/D126864



More information about the cfe-commits mailing list