VLA size in typedef

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

VLA size in typedef

Fangrui Song via cfe-dev
I want to extend the VLA size checker to recognize invalid conditions if the VLA is used through a typedef. But the typedef statement seems to be not evaluated, the VLA size value is not known by the analyzer.

The following code produces a warning:
void check_uninit_sized_VLA() {
  int x;
  int vla[x]; // expected-warning{{Declared variable-length array (VLA) uses a garbage value as its size}}
}

But the following does not:
void check_uninit_sized_VLA() {
  int x;
  typedef int VLA[x];
  VLA vla; // value of 'x' is Unknown here, why ?
}

The `checkPreStmt` with `Decl*` is not called for `TypedefDecl`.
Similarly, at a `sizeof(VLA)`  in the code above `x` is always Unknown.
How is it possible (if it is) to obtain value of `x` in these cases, or find a way to check validity of the VLA in the typedef (or a `sizeof` call)?


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: VLA size in typedef

Fangrui Song via cfe-dev

Not deeply familiar with the relevant analyzer code, but it looks like the analyzer just isn’t aware that it needs to evaluate typedefs.  Try comparing CFGBuilder::VisitDeclSubExpr to CodeGenFunction::EmitDecl/CodeGenFunction::EmitVariablyModifiedType.

 

-Eli

 

From: cfe-dev <[hidden email]> On Behalf Of Balázs Kéri via cfe-dev
Sent: Friday, April 3, 2020 3:55 AM
To: [hidden email]
Subject: [EXT] [cfe-dev] VLA size in typedef

 

I want to extend the VLA size checker to recognize invalid conditions if the VLA is used through a typedef. But the typedef statement seems to be not evaluated, the VLA size value is not known by the analyzer.

 

The following code produces a warning:

void check_uninit_sized_VLA() {

  int x;

  int vla[x]; // expected-warning{{Declared variable-length array (VLA) uses a garbage value as its size}}

}

 

But the following does not:

void check_uninit_sized_VLA() {

  int x;

  typedef int VLA[x];

  VLA vla; // value of 'x' is Unknown here, why ?

}

 

The `checkPreStmt` with `Decl*` is not called for `TypedefDecl`.

Similarly, at a `sizeof(VLA)`  in the code above `x` is always Unknown.

How is it possible (if it is) to obtain value of `x` in these cases, or find a way to check validity of the VLA in the typedef (or a `sizeof` call)?

 


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: VLA size in typedef

Fangrui Song via cfe-dev
On Fri, Apr 3, 2020 at 3:24 PM Eli Friedman via cfe-dev
<[hidden email]> wrote:
>
> Not deeply familiar with the relevant analyzer code, but it looks like the analyzer just isn’t aware that it needs to evaluate typedefs.  Try comparing CFGBuilder::VisitDeclSubExpr to CodeGenFunction::EmitDecl/CodeGenFunction::EmitVariablyModifiedType.

I'm guessing the analyzer is similarly unaware of evaluations within
typically unevaluated contexts like sizeof.

~Aaron

>
>
>
> -Eli
>
>
>
> From: cfe-dev <[hidden email]> On Behalf Of Balázs Kéri via cfe-dev
> Sent: Friday, April 3, 2020 3:55 AM
> To: [hidden email]
> Subject: [EXT] [cfe-dev] VLA size in typedef
>
>
>
> I want to extend the VLA size checker to recognize invalid conditions if the VLA is used through a typedef. But the typedef statement seems to be not evaluated, the VLA size value is not known by the analyzer.
>
>
>
> The following code produces a warning:
>
> void check_uninit_sized_VLA() {
>
>   int x;
>
>   int vla[x]; // expected-warning{{Declared variable-length array (VLA) uses a garbage value as its size}}
>
> }
>
>
>
> But the following does not:
>
> void check_uninit_sized_VLA() {
>
>   int x;
>
>   typedef int VLA[x];
>
>   VLA vla; // value of 'x' is Unknown here, why ?
>
> }
>
>
>
> The `checkPreStmt` with `Decl*` is not called for `TypedefDecl`.
>
> Similarly, at a `sizeof(VLA)`  in the code above `x` is always Unknown.
>
> How is it possible (if it is) to obtain value of `x` in these cases, or find a way to check validity of the VLA in the typedef (or a `sizeof` call)?
>
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev