Skip to content

[clang][BoundsSafety] Extend -Wvla-potential-size-confusion for struct fields and bounds annotations #129783

@rapidsna

Description

@rapidsna

#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-attributes flag:
constexpr int n;
struct foo {
  int * ptr __counted_by(n);
  int n;
};

Metadata

Metadata

Assignees

Labels

clang:bounds-safetyIssue/PR relating to the experimental -fbounds-safety feature in Clangclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions