]> granicus.if.org Git - clang/commitdiff
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@264991 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 43195bd64ff2d98fb9735cab12fab3bd9710b970..ee39401d48a94a83141f72abe48f9c385c0eb85d 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 67cde10bf45dcdde7c32238c2d1b1d65b80b80c6..55ce4a0da031b8e928e440b6b1dc842a27ed6413 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;
+}
+}