[clang] [Clang][AST] Fix crash in APValue::LValueBase::getType when we have invalid decl (PR #75130)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 15 07:07:33 PST 2023
================
@@ -70,11 +70,13 @@ QualType APValue::LValueBase::getType() const {
// constexpr int *p = &arr[1]; // valid?
//
// For now, we take the most complete type we can find.
- for (auto *Redecl = cast<ValueDecl>(D->getMostRecentDecl()); Redecl;
+ for (auto *Redecl = cast<ValueDecl>(D->getMostRecentDecl());
+ Redecl && !Redecl->isInvalidDecl();
----------------
erichkeane wrote:
This doesn't seem right to me... this change makes us skip the 'right' answer when there is a redecl in the way.
In reality, I wonder if this whole loop is misguided. If we want to just find the 'last' non-incomplete-array-type, that search is pretty easy by looping through 'redecls'. I THINK this ends up better as:
```
QualType T = D->getMostRecentDecl()->getType();
for (const auto *R : D->redecls()) { // unsure if this needs to be 'getMostRecentDecl?'
if (!R->isInvalidDecl() && !R->getType()->isIncompleteArrayType())
T = R->getType();
}
return T;
```
`redecl_iterator` is a forward-iterator, else I'd suggest just doing an rbegin/rend type thing on them.
https://github.com/llvm/llvm-project/pull/75130
More information about the cfe-commits
mailing list