[cfe-dev] AST for expresions in array sizes
David Blaikie via cfe-dev
cfe-dev at lists.llvm.org
Mon Oct 1 11:55:41 PDT 2018
I chatted with Richard Smith about this and he pointed out that the extra
info for MAX * 3 is stored in the TypeLocInfo (which can be retrieved from
the VarDecl), rather than the Type itself.
For example, in gdb, once I've found the VarDecl (pointer stored in the GDB
temporary expression $10), I could retrieve the expression:
BinaryOperator 0xcc8f7c8 'int' '*'
|-IntegerLiteral 0xcc8f788 'int' 10
`-IntegerLiteral 0xcc8f7a8 'int' 3
You can find the macro details by looking at the source location stuff - I
don't know that piece in detail, but should work as well/in the same way
here as in the rest of the AST.
Hope that helps!
On Mon, Oct 1, 2018 at 3:35 AM Dávid Bolvanský via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> #define MAX 10
> int main() // (int n)
> char arr[MAX * 3]; // arr[n + 3]
> I expected that AST would be more detailed (e.g. Binary Operator) but
> Clang seems to fold it:
> `-FunctionDecl <line:11:1, line:14:1> line:11:5 main 'int ()'
> `-CompoundStmt <line:12:1, line:14:1>
> `-DeclStmt <line:13:3, col:20>
> `-VarDecl <col:3, col:19> col:8 arr 'char '
> or raw output
> `-VarDecl <col:3, col:15> col:8 a 'char [n * 3]'
> So with the current AST output we are unable to determine overflowing in
> array sizes, as requested in https://bugs.llvm.org/show_bug.cgi?id=27439,
> Is it possible to disable that folding / enhance VarDecl for arrays?
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev