summaryrefslogtreecommitdiff
path: root/clang/test/Analysis/initialization.cpp
AgeCommit message (Collapse)Author
2025-06-30[NFC][analyzer] Use %clang_analyze_cc1 consistently (#145895)Donát Nagy
A large majority of the LIT tests of the clang static analyzer use RUN lines with the placeholder `%clang_analyze_cc1` which expands to `%clang_cc1 -analyze -setup-static-analyzer` where the only effect of `-setup-static-analyzer` is that it ensures that the macro `__clang_analyzer__` is defined. However, there were some tests that used `%clang_cc1 -analyze` directly; this commit changes those to using `%clang_analyze_cc1` for the sake of consistency. Previously `%clang_analyze_cc1` did not work within the directory `exploded-graph-rewriter` (because that directory has its own custom `lit.local.cfg`) but this problem was eliminated by the recent commit 40cc4379cda6e0d6efe72c55d1968f9cf427a16a, so it was possible to resolve and delete the FIXME comments asking for this change. There are a few tests that use `%clang --analyze` or other command-line flags (e.g. help flags), those are not affected by this change. This cleanup was discussed in the discourse thread https://discourse.llvm.org/t/taking-ownership-of-clang-test-analysis/84689/11
2025-02-26[analyzer] Update the undefined assignment checker diagnostics to not use ↵David Tarditi
the term 'garbage' (#126596) A clang user pointed out that messages for the static analyzer undefined assignment checker use the term ‘garbage’, which might have a negative connotation to some users. This change updates the messages to use the term ‘uninitialized’. This is the usual reason why a value is undefined in the static analyzer and describes the logical error that a programmer should take action to fix. Out-of-bounds reads can also produce undefined values in the static analyzer. The right long-term design is to have to the array bounds checker cover out-of-bounds reads, so we do not cover that case in the updated messages. The recent improvements to the array bounds checker make it a candidate to add to the core set of checkers. rdar://133418644
2023-03-22[analyzer] Fix crashing getSValFromInitListExpr for nested initlistsBalazs Benics
In the following example, we will end up hitting the `llvm_unreachable()`: https://godbolt.org/z/5sccc95Ec ```lang=C++ enum class E {}; const E glob[] = {{}}; void initlistWithinInitlist() { clang_analyzer_dump(glob[0]); // crashes at loading from `glob[0]` } ``` We should just return `std::nullopt` instead for these cases. It's better than crashing. Reviewed By: xazax.hun Differential Revision: https://reviews.llvm.org/D146538
2021-11-15[analyzer] Fix region cast between the same types with different qualifiers.Denys Petrov
Summary: Specifically, this fixes the case when we get an access to array element through the pointer to element. This covers several FIXME's. in https://reviews.llvm.org/D111654. Example: const int arr[4][2]; const int *ptr = arr[1]; // Fixes this. The issue is that `arr[1]` is `int*` (&Element{Element{glob_arr5,1 S64b,int[2]},0 S64b,int}), and `ptr` is `const int*`. We don't take qualifiers into account. Consequently, we doesn't match the types as the same ones. Differential Revision: https://reviews.llvm.org/D113480
2021-11-08[analyzer] Retrieve a value from list initialization of multi-dimensional ↵Denys Petrov
array declaration. Summary: Add support of multi-dimensional arrays in `RegionStoreManager::getBindingForElement`. Handle nested ElementRegion's getting offsets and checking for being in bounds. Get values from the nested initialization lists using obtained offsets. Differential Revision: https://reviews.llvm.org/D111654
2021-10-29[analyzer] Retrieve a character from StringLiteral as an initializer for ↵Denys Petrov
constant arrays. Summary: Assuming that values of constant arrays never change, we can retrieve values for specific position(index) right from the initializer, if presented. Retrieve a character code by index from StringLiteral which is an initializer of constant arrays in global scope. This patch has a known issue of getting access to characters past the end of the literal. The declaration, in which the literal is used, is an implicit cast of kind `array-to-pointer`. The offset should be in literal length's bounds. This should be distinguished from the states in the Standard C++20 [dcl.init.string] 9.4.2.3. Example: const char arr[42] = "123"; char c = arr[41]; // OK const char * const str = "123"; char c = str[41]; // NOK Differential Revision: https://reviews.llvm.org/D107339
2021-10-25[analyzer][NFCI] Move a block from `getBindingForElement` to separate functionsDenys Petrov
Summary: 1. Improve readability by moving deeply nested block of code from RegionStoreManager::getBindingForElement to new separate functions: - getConstantValFromConstArrayInitializer; - getSValFromInitListExpr. 2. Handle the case when index is a symbolic value. Write specific test cases. 3. Add test cases when there is no initialization expression presented. This patch implies to make next patches clearer and easier for review process. Differential Revision: https://reviews.llvm.org/D106681
2021-09-24[analyzer] Retrieve a value from list initialization of constant array ↵Denys Petrov
declaration in a global scope. Summary: Fix the point that we didn't take into account array's dimension. Retrieve a value of global constant array by iterating through its initializer list. Differential Revision: https://reviews.llvm.org/D104285 Fixes: https://bugs.llvm.org/show_bug.cgi?id=50604
2019-10-19[analyzer] Specify the C++ standard in more tests.Artem Dergachev
Makes life easier for downstream developers with different default standard. llvm-svn: 375308
2018-05-29[analyzer] const init: handle non-explicit cases more accuratelyRafael Stahl
Summary: If the access is out of bounds, return UndefinedVal. If it is missing an explicit init, return the implicit zero value it must have. Reviewers: NoQ, xazax.hun, george.karpenkov Reviewed By: NoQ Subscribers: szepet, rnkovacs, a.sidorin, cfe-commits Differential Revision: https://reviews.llvm.org/D46823 llvm-svn: 333417