[clang] [clang][Static analyzer] fix crash on using `bitcast(<type>, <array>)` as array subscript (PR #101647)
Balazs Benics via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 2 03:23:12 PDT 2024
================
@@ -472,7 +472,19 @@ SVal StoreManager::getLValueElement(QualType elementType, NonLoc Offset,
const auto *ElemR = dyn_cast<ElementRegion>(BaseRegion);
// Convert the offset to the appropriate size and signedness.
- Offset = svalBuilder.convertToArrayIndex(Offset).castAs<NonLoc>();
+ auto Off = svalBuilder.convertToArrayIndex(Offset).getAs<NonLoc>();
+ if (!Off) {
+ // Handle cases when LazyCompoundVal is used for an array index.
+ // Such case is possible if code does:
+ //
+ // char b[4];
+ // a[__builtin_bitcast(int, b)];
+ //
----------------
steakhal wrote:
```suggestion
// char b[4];
// a[__builtin_bitcast(int, b)];
```
https://github.com/llvm/llvm-project/pull/101647
More information about the cfe-commits
mailing list