danielmarjamaki created this revision. danielmarjamaki added a reviewer: NoQ. danielmarjamaki added a subscriber: cfe-commits. danielmarjamaki set the repository for this revision to rL LLVM.
This fix the crash reported in https://llvm.org/bugs/show_bug.cgi?id=31173 Repository: rL LLVM https://reviews.llvm.org/D28297 Files: lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp test/Analysis/cast-to-struct.cpp Index: test/Analysis/cast-to-struct.cpp =================================================================== --- test/Analysis/cast-to-struct.cpp +++ test/Analysis/cast-to-struct.cpp @@ -65,3 +65,8 @@ 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; +} Index: lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp +++ lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp @@ -55,6 +55,12 @@ if (!ToPointeeTy->isStructureOrClassType()) return true; + if (const RecordType *RD = dyn_cast<RecordType>(ToPointeeTy.getTypePtr())) { + if (!RD->getDecl()->getDefinition()) { + return true; + } + } + // We allow cast from void*. if (OrigPointeeTy->isVoidType()) return true;
Index: test/Analysis/cast-to-struct.cpp =================================================================== --- test/Analysis/cast-to-struct.cpp +++ test/Analysis/cast-to-struct.cpp @@ -65,3 +65,8 @@ 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; +} Index: lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp +++ lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp @@ -55,6 +55,12 @@ if (!ToPointeeTy->isStructureOrClassType()) return true; + if (const RecordType *RD = dyn_cast<RecordType>(ToPointeeTy.getTypePtr())) { + if (!RD->getDecl()->getDefinition()) { + return true; + } + } + // We allow cast from void*. if (OrigPointeeTy->isVoidType()) return true;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits