The value type can be a typedef of a reference (e.g. typedef int& myint).
In this case GetQualType(type) will return clang::Typedef, which cannot
be casted to clang::ReferenceType.
Fix a regression introduced in https://reviews.llvm.org/D103532.
Differential D113673
[lldb] Unwrap the type when dereferencing the value werat on Nov 11 2021, 6:40 AM. Authored by
Details
The value type can be a typedef of a reference (e.g. typedef int& myint). Fix a regression introduced in https://reviews.llvm.org/D103532.
Diff Detail
Event TimelineComment Actions I was trying to fix this a while back in D108717 but got distracted and did not get back to it. Comment Actions Thanks a lot for fixing this, could you point to D103532 as the cause for the regression in the commit message? This LGTM in general, but I think there could still be some obscure cases where this could fail. So the switch statement this code is in (and which detects whether its a reference type) is defined as: clang::QualType parent_qual_type( RemoveWrappingTypes(GetCanonicalQualType(type))); switch (parent_qual_type->getTypeClass()) { GetCanonicalQualType should strip all the outer and inner type sugar there is. And RemoveWrappingTypes removes *most* of the outer type sugar (which isn't necessary anymore as it should be all gone), but also makes types non-atomic (for simplicity reasons). Meanwhile in our reference-case code we try to remove the outer type sugar (and atomic) via RemoveWrappingTypes. And if this doesn't end up in a ReferenceType the cast fails. So IIUC there is still a possibility that we fail to cast here in case GetCanonicalQualType removes more outer sugar than RemoveWrappingTypes, which I think can only happen for type sugar classes not implemented by RemoveWrappingTypes (e.g., a quick grep tells me AttributedType and some template stuff is sugar that we don't handle). So I would propose we do the following:
|
nit: Could you give this a more unique name such as td_to_ref_type?