================
@@ -1198,16 +1204,33 @@ bool createParameters(NewFunction &ExtractedFunc,
       }
     }
 
+    // A reference-to-array parameter's declared type always spells out
+    // every dimension's bound, including the outermost one (unlike a
+    // decayed C pointer, which drops it). For a variable-length array,
+    // that bound is an arbitrary expression -- typically another
+    // variable's name -- that isn't in scope in the extracted
+    // function's declaration, and even making it an explicit preceding
+    // parameter doesn't help: the two don't line up at the call site
+    // (the callee's declared bound and the caller's concrete array type
+    // don't reference-bind just because both happen to be named the
+    // same). So this is rejected unconditionally, in both languages --
+    // C still gets a chance to extract it below, by decaying to a
+    // pointer instead of keeping a reference.
+    if (Kind == ParamPassKind::Reference && TypeInfo->isArrayType() &&
+        TypeInfo->isVariablyModifiedType() && LangOpts.CPlusPlus)
----------------
ArcsinX wrote:

Maybe we can also add a check for pointers to VLA.
E.g. this case produces uncompilable code
```cpp
void foo(int N) {
   int (*A)[N];
   [[ (*A)[0] = 1; ]]
}
```

https://github.com/llvm/llvm-project/pull/230046
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to