From: Richard Trieu Date: Thu, 31 Mar 2016 04:18:07 +0000 (+0000) Subject: Fix -Wdynamic-class-memaccess to skip invalid classes. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bb39104647b6bc81ba627642f31c4487eeb59e8e;p=clang Fix -Wdynamic-class-memaccess to skip invalid classes. This warning sometimes will infinitely recurse on CXXRecordDecl's from ill-formed recursive classes that have fields of themselves. Skip processing these classes to prevent this from happening. Fixes https://llvm.org/bugs/show_bug.cgi?id=27142 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@264991 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 43195bd64f..ee39401d48 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -5611,7 +5611,7 @@ static const CXXRecordDecl *getContainedDynamicClass(QualType T, const CXXRecordDecl *RD = Ty->getAsCXXRecordDecl(); RD = RD ? RD->getDefinition() : nullptr; - if (!RD) + if (!RD || RD->isInvalidDecl()) return nullptr; if (RD->isDynamicClass()) diff --git a/test/SemaCXX/warn-bad-memaccess.cpp b/test/SemaCXX/warn-bad-memaccess.cpp index 67cde10bf4..55ce4a0da0 100644 --- a/test/SemaCXX/warn-bad-memaccess.cpp +++ b/test/SemaCXX/warn-bad-memaccess.cpp @@ -141,3 +141,16 @@ namespace N { N::memset(&x1, 0, sizeof x1); } } + +namespace recursive_class { +struct S { + S v; + // expected-error@-1{{field has incomplete type 'recursive_class::S'}} + // expected-note@-3{{definition of 'recursive_class::S' is not complete until the closing '}'}} +} a; + +int main() { + __builtin_memset(&a, 0, sizeof a); + return 0; +} +}