Skip to content
Snippets Groups Projects
Commit 0bdcd308 authored by Daniel Marjamaki's avatar Daniel Marjamaki
Browse files

[analyzer] Fix crashes in CastToStruct checker for undefined structs

This crash was reported in https://bugs.llvm.org//show_bug.cgi?id=31173

Differential Revision: https://reviews.llvm.org/D28297


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@297187 91177308-0d34-0410-b5e6-96231b3b80d8
parent 28e06304
No related branches found
No related tags found
No related merge requests found
......@@ -84,6 +84,10 @@ bool CastToStructVisitor::VisitCastExpr(const CastExpr *CE) {
if (!VD || VD->getType()->isReferenceType())
return true;
if (ToPointeeTy->isIncompleteType() ||
OrigPointeeTy->isIncompleteType())
return true;
// Warn when there is widening cast.
unsigned ToWidth = Ctx.getTypeInfo(ToPointeeTy).Width;
unsigned OrigWidth = Ctx.getTypeInfo(OrigPointeeTy).Width;
......
......@@ -65,3 +65,17 @@ void intToStruct(int *P) {
void *VP = P;
Abc = (struct ABC *)VP;
}
// https://llvm.org/bugs/show_bug.cgi?id=31173
void dontCrash1(struct AB X) {
struct UndefS *S = (struct UndefS *)&X;
}
struct S;
struct T {
struct S *P;
};
extern struct S Var1, Var2;
void dontCrash2() {
((struct T *) &Var1)->P = &Var2;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment