[PATCH] D28297: [StaticAnalyzer] Fix crash in CastToStructChecker
Daniel Marjamäki via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 4 09:11:47 PST 2017
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28297.83062.patch
Type: text/x-patch
Size: 943 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170104/42a301b8/attachment.bin>
More information about the cfe-commits
mailing list