Fixed bug with checking the kind of types.

The isLValueReferenceType function checks to see if the QualType's
canonical type is an LValue reference, and not if the QualType
itself is an LValue reference.  This caused a segfault when trying
to cast the QualType's Type to a LValueReference.  This is now
fixed by casting the result of getCanonicalType().

In addition, a test was added to isConsumableType to prevent
segfaults when a type being tested by the analysis is a reference
to a pointer or a pointer to a reference.

llvm-svn: 193751
This commit is contained in:
Chris Wailes 2013-10-31 15:38:12 +00:00
parent aca9739a1a
commit 93edffa8fe
1 changed files with 8 additions and 4 deletions

View File

@ -142,10 +142,13 @@ static bool isCallableInState(const CallableWhenAttr *CWAttr,
}
static bool isConsumableType(const QualType &QT) {
if (QT->isPointerType() || QT->isReferenceType())
return false;
if (const CXXRecordDecl *RD = QT->getAsCXXRecordDecl())
return RD->hasAttr<ConsumableAttr>();
else
return false;
return false;
}
static bool isKnownState(ConsumedState State) {
@ -163,7 +166,8 @@ static bool isKnownState(ConsumedState State) {
static bool isRValueRefish(QualType ParamType) {
return ParamType->isRValueReferenceType() ||
(ParamType->isLValueReferenceType() &&
!cast<LValueReferenceType>(*ParamType).isSpelledAsLValue());
!cast<LValueReferenceType>(
ParamType.getCanonicalType())->isSpelledAsLValue());
}
static bool isTestingFunction(const FunctionDecl *FunDecl) {
@ -864,7 +868,7 @@ void ConsumedStmtVisitor::VisitParmVarDecl(const ParmVarDecl *Param) {
const ParamTypestateAttr *PTAttr = Param->getAttr<ParamTypestateAttr>();
ParamState = mapParamTypestateAttrState(PTAttr);
} else if (isValueType(ParamType) && isConsumableType(ParamType)) {
} else if (isConsumableType(ParamType)) {
ParamState = mapConsumableAttrState(ParamType);
} else if (isRValueRefish(ParamType) &&