llvm-project
llvm-project copied to clipboard
[clang][BoundsSafety] Extend `-Wvla-potential-size-confusion` for struct fields and bounds annotations
https://github.com/llvm/llvm-project/pull/129772
-Wvla-potential-size-confusion diagnoses when n references the file scope variable and not the parameter.
int n;
void func(int array[n], int n);
We may want to extend it to diagnose on situations mentioned in the PR:
- Diagnosing a similar situation in structures. e.g.,
int n;
struct S {
int n;
int array[sizeof(n)]; // Refers to outer n, not member n
};
- Diagnosing with constant-size arrays (requires tracking the expression for the constant-size array in the
QualType) e.g.,
constexpr int n = 12;
void func(int array[n], int n);
- Potentially, also diagnosing with any ambiguous situations with bounds annotations like below (with or without the
-fexperimental-late-parse-attributesflag:
constexpr int n;
struct foo {
int * ptr __counted_by(n);
int n;
};
@llvm/issue-subscribers-clang-frontend
Author: Yeoul Na (rapidsna)
https://github.com/llvm/llvm-project/pull/129772
-Wvla-potential-size-confusion diagnoses when n references the file scope variable and not the parameter.
int n;
void func(int array[n], int n);
We may want to extend it to diagnose on situations mentioned in the PR:
- Diagnosing a similar situation in structures. e.g.,
int n;
struct S {
int n;
int array[sizeof(n)]; // Refers to outer n, not member n
};
- Diagnosing with constant-size arrays (requires tracking the expression for the constant-size array in the
QualType) e.g.,
constexpr int n = 12;
void func(int array[n], int n);
- Potentially, also diagnosing with any ambiguous situations with bounds annotations like below (with or without the
-fexperimental-late-parse-attributesflag:
constexpr int n;
struct foo {
int * ptr __counted_by(n);
int n;
};
@AaronBallman