[PATCH] Allow transformation of VariableArray to ConstantArray.

Richard Smith richard at metafoo.co.uk
Tue Feb 4 12:12:01 PST 2014



================
Comment at: lib/Sema/TreeTransform.h:3932-3936
@@ -3931,3 +3931,7 @@
 
-  VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
+  ArrayTypeLoc NewTL;
+  if (Result->getTypeClass() == Type::ConstantArray)
+    NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
+  else
+    NewTL = TLB.push<VariableArrayTypeLoc>(Result);
   NewTL.setLBracketLoc(TL.getLBracketLoc());
----------------
Here's what `TransformDependentSizedArrayType` does:

  // We might have any sort of array type now, but fortunately they
  // all have the same location layout.
  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);

Maybe do the same here?

================
Comment at: test/SemaCXX/crashes.cpp:235
@@ +234,3 @@
+
+namespace pr18633 {
+  struct A1 {
----------------
David Blaikie wrote:
> While the existence of this test file might imply otherwise - in my opinion, we should never simply have a test that "doesn't crash". There must be some ultimate behavior expected of the compiler that was never reached due to the crash - that's missing test coverage that should be added.
> 
> (also, presumably there are some related test cases in a more specific test file somewhere that this should be grouped with, perhaps - either the non-templated case, or a template test that tests some similar functionality but missed this case (but I know it's sometimes hard to track down the right test cases - sometimes it can be done by evoking diagnostics for similar features - but since this test has no diagnostics I guess it should be a codegen test))
Agreed. This test should check that (for instance) we can apply 'sizeof' to the resulting array type and get the right constant size back.

It'd also be good to run this test with -pedantic and ensure that we do get the 'VLA' extension warning here (it's not quite the right diagnostic, but -- pending feedback from CWG -- we do want to reject this code in strictly-conforming mode).


http://llvm-reviews.chandlerc.com/D2688



More information about the cfe-commits mailing list