forked from OSchip/llvm-project
[analyzer] Fix crash in CastToStruct when there is no record definition
This crash was reported in https://bugs.llvm.org//show_bug.cgi?id=31173 Differential Revision: https://reviews.llvm.org/D28297 llvm-svn: 295545
This commit is contained in:
parent
93748ebf82
commit
1149166bb9
|
@ -84,6 +84,13 @@ bool CastToStructVisitor::VisitCastExpr(const CastExpr *CE) {
|
|||
if (!VD || VD->getType()->isReferenceType())
|
||||
return true;
|
||||
|
||||
// Don't warn when target type has no definition.
|
||||
if (const RecordType *RD = dyn_cast<RecordType>(ToPointeeTy.getTypePtr())) {
|
||||
if (!RD->getDecl()->getDefinition()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Warn when there is widening cast.
|
||||
unsigned ToWidth = Ctx.getTypeInfo(ToPointeeTy).Width;
|
||||
unsigned OrigWidth = Ctx.getTypeInfo(OrigPointeeTy).Width;
|
||||
|
|
|
@ -65,3 +65,8 @@ void intToStruct(int *P) {
|
|||
void *VP = P;
|
||||
Abc = (struct ABC *)VP;
|
||||
}
|
||||
|
||||
// https://llvm.org/bugs/show_bug.cgi?id=31173
|
||||
void dontCrash(struct AB X) {
|
||||
struct UndefS *S = (struct UndefS *)&X;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue