[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-30 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment. In D104285#2972215 , @martong wrote: > @ASDenysPetrov Denis, do you think it would make sense to handle the > non-multi-dimensional cases first? I see that you have useful patches in the > stack that depends on this change

[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-30 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment. @ASDenysPetrov Denis, do you think it would make sense to handle the non-multi-dimensional cases first? I see that you have useful patches in the stack that depends on this change (i.e handling a StringLiteral or a CompoundLiteralExpr) but perhaps they would be meaningf

[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-26 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 368905. ASDenysPetrov edited the summary of this revision. ASDenysPetrov added a comment. Reworked the patch according to the discussion and taking UB into account. Moved `Expr::getExprForConstArrayByRawIndex` to `RegionStoreManager`. CHANGES SINCE LA

[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-18 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment. In D104285#2951911 , @ASDenysPetrov wrote: > This is really significant obstructions. As what I see the only thing left > for us is to wait until the Standard transforms this //shenanigans// into > legal operations and be

[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-18 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment. @aaron.ballman Now I'm going to rework this patch according to our disscussion. This is the first patch in the stack as you can see. And I don't want to loose the series of improvements so I will adjust it to save further patches. CHANGES SINCE LAST ACTION htt

[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-18 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment. In D104285#2949772 , @aaron.ballman wrote: > I don't think that compilers will create a disjointed multidimensional array, > as that would waste space at runtime. However, I do think that *optimizers* > are getting much s

[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment. In D104285#2949638 , @ASDenysPetrov wrote: > @aaron.ballman > Let me speak some thoughts. Consider next: > > int arr[2][5]; > int *ptr1 = &arr[0][0]; > int *ptr2 = &arr[1][0]; > > The Standard tells that `ptr1[5]` is

[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-17 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment. @aaron.ballman Let me speak some thoughts. Consider next: int arr[2][5]; int *ptr1 = &arr[0][0]; int *ptr2 = &arr[1][0]; The Standard tells that `ptr1[5]` is UB and `ptr2[0]` is a valid object. In practice `ptr1` and `ptr2` usually are equal. But the Standar

[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment. In D104285#2949273 , @ASDenysPetrov wrote: > @aaron.ballman > Ok, I got your concerns. Thanks for sticking with me! > As I can see we shall only reason about objects within the bounds. Otherwise, > we shall return `Undef

[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-17 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment. @aaron.ballman Ok, I got your concerns. As I can see we shall only reason about objects within the bounds. Otherwise, we shall return `UndefinedVal`. E.g.: int arr[2][5]; int* ptr1= (int*)arr; // Valid indexing for `ptr` is in range [0,4]. int* ptr2 = &arr[0]

[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment. In D104285#2947255 , @ASDenysPetrov wrote: > In D104285#2943449 , @aaron.ballman > wrote: > >> One thing I think is worth asking in this thread is whether what you're >> analyzing

[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-16 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment. In D104285#2943449 , @aaron.ballman wrote: > One thing I think is worth asking in this thread is whether what you're > analyzing is undefined behavior? Technically you are right. Every exit out of an array extent is UB ac

[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment. One thing I think is worth asking in this thread is whether what you're analyzing is undefined behavior? Array subscripting is defined in terms of pointer addition per: http://eel.is/c++draft/expr.sub#1 Pointer addition has a special behavior for arrays: http://e

[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-13 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 366209. ASDenysPetrov added a comment. Fixed //smell// code: from `isa'n'cast` to `dyn-cast`. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D104285/new/ https://reviews.llvm.org/D104285 Files: clang/include/clang/AST/Expr.h clang/include/c

[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-12 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 366009. ASDenysPetrov added a comment. Changed according to comments. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D104285/new/ https://reviews.llvm.org/D104285 Files: clang/include/clang/AST/Expr.h clang/include/clang/AST/Type.h clang/

[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-05 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment. @aaron.ballman Thanks for the review and comments. I'll update it ASAP. Comment at: clang/include/clang/AST/Expr.h:4959 + /// Return an value-expression under the given index. + /// aaron.ballman wrote: > +1 ===

[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments. Comment at: clang/include/clang/AST/Expr.h:4959 + /// Return an value-expression under the given index. + /// Comment at: clang/include/clang/AST/Expr.h:4970 + /// - `this` if there's no expression for

[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-07-29 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment. @martong I've added new reviewers, thanks for the prompt. > E.g. could we have a free function outside of the `InitListExpr` to implement > `getExprForConstArrayByRawIndex` It is possible, but I think this is more naturaly for the instance of `InitListExpr` to be