Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

GNU extension: Support forward declaring function parameters #47242

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR48273
Status NEW
Importance P enhancement
Reported by Joseph C. Sible (josephcsible@gmail.com)
Reported on 2020-11-23 12:06:30 -0800
Last modified on 2020-11-23 16:26:57 -0800
Version 11.0
Hardware Other Linux
CC htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Consider this C function:

void transpose(double (*)[*], int);
void transpose(array, size)
  int size;
  double (*array)[size];
{
  for (int i=1; i<size; i++)
  {
    for (int j=0; j<i; j++)
    {
      double t = array[i][j];
      array[i][j] = array[j][i];
      array[j][i] = t;
    }
  }
}

It uses a K&R function definition, which is deprecated and will probably be
removed in C2x. To my knowledge, there's no standard replacement for that since
the VLA comes before its size, but a GNU extension allows forward declaring
parameters, like this:

void transpose(double (*)[*], int);
void transpose(int size; double (*array)[size], int size)
{
  for (int i=1; i<size; i++)
  {
    for (int j=0; j<i; j++)
    {
      double t = array[i][j];
      array[i][j] = array[j][i];
      array[j][i] = t;
    }
  }
}

Today, GCC will accept that code, but Clang will not. Can support for that GNU
extension be added to Clang as well?
Quuxplusone commented 3 years ago

For future readers: this GCC extension is (slightly) documented here: https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html