Issue 151744
Summary New dialect flag: -farray-parameters-are-arrays
Labels new issue
Assignees
Reporter alejandro-colomar
    GCC ticket: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121331>

Cc: @AaronBallman 

This is a stronger version of -farray-parameters-are-const, proposed in
<https://github.com/llvm/llvm-project/issues/151526>.

It would make array parameters work as real arrays in every way: sizeof(), typeof(), _Generic(), ...

This would affect the function scope, but not it's callers.

Let's write some examples, to make it clear:

```c
	void
	f(int size, char buf[size], pid_t pid)
	{
		if (stprintf(buf, _Countof(buf), "/proc/%d/", pid) == -1)
			return;
		...
		return;
	}

	char *a = malloc(100);
	f(100, a, 0);  // Ok; at call site pointers are valid.

	void
	g(int size, char buf[size], pid_t pid)
	{
		buf = NULL;  // error: assignment to _expression_ with array type
	}

	void
	h(char *buf;
	  int size, char buf[size], pid_t pid);  // error: redeclaration with different type

	void
	i(char buf[];
	  int size, char buf[size], pid_t pid);  // okay

	void
	i(char buf[size];
	  int size, char buf[size], pid_t pid);  // okay
```

This is a breaking change, so it must be opt-in.

However, there shouldn't be much code that is relying on the old behavior, as most of it is already diagnosed by default.

---

With this flag enabled, the only difference with real arrays would be that these could be null.  Other than that, they'd be real arrays.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to