llvm / llvm/llvm-project

Reject unsupported `__counted_by` use cases in nested contexts

Open
#166,454 0 comments 0 reactions 0 assignees View on GitHub
clang:bounds-safety
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

`__counted_by` should not be allowed to reference struct members from within nested contexts, as this is not supported.

The following cases should be rejected with clear diagnostics:

```C
struct counted_by_function_pointer_param_late {
int (*callback)(int *__counted_by(len)); // Should error: cannot reference member from nested context
int len;
};

struct counted_by_function_pointer_param {
int len;
int (*callback)(int *__counted_by(len)); // Should error: cannot reference member from nested context
};
```

### Current behavior:

These cases are currently accepted by the compiler.

### Expected behavior:

The compiler should reject __counted_by attributes that attempt to reference struct members from within nested contexts (such as function pointer parameter types), regardless of whether the referenced member is declared before or after.

### Rationale:

Referring to a struct member from a nested context is not supported and should be diagnosed as an error.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.