[PATCH] D90871: [Sema] Fold VLAs to constant arrays in a few more contexts
Richard Smith - zygoloid via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 29 23:51:36 PST 2020
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.
Thanks, that's very clean.
================
Comment at: clang/lib/Sema/SemaDecl.cpp:6027
+/// Attempt to fold a variable-sized type to a constant-sized type, returning
+/// true if it we were successful.
+static bool tryToFixVariablyModifiedVarType(Sema &S, TypeSourceInfo *&TInfo,
----------------
Typo "it we"
================
Comment at: clang/lib/Sema/SemaDecl.cpp:6899-6901
+ if (D.hasInitializer() && R->isVariablyModifiedType())
+ tryToFixVariablyModifiedVarType(*this, TInfo, R, D.getIdentifierLoc(),
+ /*DiagID=*/0);
----------------
Is there a reason to make this C-specific? We support VLAs in C++ as an extension; it'd seem reasonable to do this folding as an extension too, if it's as simple as moving the new code out of the `if (!C++)`.
================
Comment at: clang/test/Sema/vla.c:104
+
+void test_fold_to_constant_array() {
+ const int ksize = 4;
----------------
Can you also add a positive test? Eg, a `goto` over one of the folded-to-constant cases, to show that we can jump over those. (As-is, this test ensures that we produce the warning, but not that we actually treat the array variable as not being a VLA.)
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D90871/new/
https://reviews.llvm.org/D90871
More information about the cfe-commits
mailing list