[PATCH] D123763: [randstruct] Enforce using a designated init for a randomized struct

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 14 05:49:43 PDT 2022


aaron.ballman added a comment.

Thank you for this!

Because we're not checking anything about the randomized output or the AST nodes directly, this should be tested through the usual `lit` tests instead of using a unit test.



================
Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:11591-11596
+// Layout randomization diagnostics.
+def err_non_designated_init_used : Error<
+  "non-designated initializers cannot be used on a randomized struct">;
 def err_cast_from_randomized_struct : Error<
   "casting from randomized structure pointer type %0 to %1">;
+
----------------



================
Comment at: clang/unittests/AST/RandstructTest.cpp:484
+  EXPECT_EQ(Diags.getNumErrors(), 1u);
+}
+
----------------
Other things to test:
```
struct test t1 = {}; // This should be fine per WG14 N2900 (in C23) + our extension handling of it in earlier modes
struct test t2 = {0}; // This should also be fine per C99 6.7.8p19
struct test t3 = { .a = foo, bar, baz }; // Error

struct other_test {
  func_ptr a;
  func_ptr b[3];
  func_ptr c;
};

struct other_test t4 = { .a = foo, .b[0] = foo }; // Ok
struct other_test t5 = { .a = foo, .b[0] = foo, bar, baz }; // Ok
struct other_test t6 = { .a = foo, .b[0] = foo, bar, baz, gaz }; // Error
struct other_test t7 = { .a = foo, .b = { foo, bar, baz } }; // Ok
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123763



More information about the cfe-commits mailing list