On Tue, Jul 29, 2025 at 11:13 AM Yeoul Na <yeoul...@apple.com> wrote:
>
>
> On Jul 28, 2025, at 5:54 PM, Bill Wendling <mo...@google.com> wrote:
>
> On Mon, Jul 28, 2025 at 4:52 PM Yeoul Na <yeoul...@apple.com> wrote:
>
>
> Could someone working on Linux answer my earlier question? Working on a 
> compromise solution is one thing, but I’m trying to understand the situation 
> better.
>
> Out of curiosity, do you think focusing on simple identifier cases (which, as 
> I understand, are the majority in the Linux kernel as well) would allow us to 
> make meaningful progress for now? My assumption is that even such simple use 
> cases (e.g., __counted_by(field) on a pointer field) are yet to be widely 
> adopted across the Linux codebases, but I’d love to hear your perspective.
>
>
>
> This is one of Kees's and my goals for the year. (Well, full
> __counted_by() on pointers in structs, not just single identifiers.) I
> think GCC recently added support for them, so we could progress
> somewhat with this. But Kees brought up several examples over
> different threads about how Linux would theoretically use the feature.
> They include, but aren't limited to, calling functions (e.g. byte
> swapping) and using variables outside of the struct. He may have many
> more examples, but those are two that I recall off the top of my head.
>
>
> Agree. Fwiw, our proposal for WG14 also discusses that the paragraph before 
> “Simple identifiers only” section in page 7  
> https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3656.pdf.
>
> “… For example, __counted_by does not permit the expression to contain 
> arbitrary side-effects, which is implemented with a syntactic
> check preventing assignments, (most) function calls, and common extensions 
> like statement-expressions. If it would
> make a late-parsing-like solution more acceptable to other implementations, 
> we think it would be reasonable for the
> committee to impose similar restrictions grammatically, thus reducing the 
> size of the grammar that must be accepted
> by the “late parser”. If this went as far as forbidding casts, it would 
> actually reduce the expression grammar to a
> context-free subset and allow the actual parsing to be done eagerly, although 
> semantic analysis would still need to
> be delayed until all the peers were known.”
>
> Btw, could you remind me what was the byte swapping example? I couldn’t find 
> it.
>
It's in one of his responses earlier in this thread:

struct S {
  struct header hdr;
  __be32 bytes;
  struct info array[] __counted_by(be32_to_cpu(bytes) / sizeof(struct info));
};

According to what @hnrklssn said this should be an acceptable
expression if 'be32_to_cpu' is marked as 'const'.

-bw

Reply via email to