Fix -Wdynamic-class-memaccess to skip invalid classes.
authorRichard Trieu <rtrieu@google.com>
Thu, 31 Mar 2016 04:18:07 +0000 (04:18 +0000)
committerRichard Trieu <rtrieu@google.com>
Thu, 31 Mar 2016 04:18:07 +0000 (04:18 +0000)
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

llvm-svn: 264991

clang/lib/Sema/SemaChecking.cpp
clang/test/SemaCXX/warn-bad-memaccess.cpp

index 43195bd..ee39401 100644 (file)
@@ -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())
index 67cde10..55ce4a0 100644 (file)
@@ -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;
+}
+}