[analyzer] Add test for a crash fixed in r338775.

Do not crash if a CXXRecordDecl cannot be obtained for an object.

Special thanks for the reproduction to Alexander Kornienko.

llvm-svn: 338918
This commit is contained in:
Reka Kovacs 2018-08-03 20:42:02 +00:00
parent 4dfe279e00
commit bfd9cfdeeb
2 changed files with 11 additions and 4 deletions

View File

@ -133,10 +133,7 @@ bool InnerPointerChecker::isCalledOnStringObject(
return false;
CXXRecordDecl *Decl = ObjTy->getAsCXXRecordDecl();
if (!Decl || Decl->getName() != "basic_string")
return false;
return true;
return Decl && Decl->getName() == "basic_string";
}
bool InnerPointerChecker::isInvalidatingMemberFunction(

View File

@ -382,3 +382,13 @@ const char *escape_via_return_local() {
// expected-note@-1 {{Inner pointer invalidated by call to destructor}}
} // expected-warning {{Use of memory after it is freed}}
// expected-note@-1 {{Use of memory after it is freed}}
char *c();
class A {};
void no_CXXRecordDecl() {
A a, *b;
*(void **)&b = c() + 1;
*b = a; // no-crash
}