r264991 - Fix -Wdynamic-class-memaccess to skip invalid classes.
Richard Trieu via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 30 21:18:07 PDT 2016
Author: rtrieu
Date: Wed Mar 30 23:18:07 2016
New Revision: 264991
URL: http://llvm.org/viewvc/llvm-project?rev=264991&view=rev
Log:
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
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaCXX/warn-bad-memaccess.cpp
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=264991&r1=264990&r2=264991&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Mar 30 23:18:07 2016
@@ -5611,7 +5611,7 @@ static const CXXRecordDecl *getContained
const CXXRecordDecl *RD = Ty->getAsCXXRecordDecl();
RD = RD ? RD->getDefinition() : nullptr;
- if (!RD)
+ if (!RD || RD->isInvalidDecl())
return nullptr;
if (RD->isDynamicClass())
Modified: cfe/trunk/test/SemaCXX/warn-bad-memaccess.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-bad-memaccess.cpp?rev=264991&r1=264990&r2=264991&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-bad-memaccess.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-bad-memaccess.cpp Wed Mar 30 23:18:07 2016
@@ -141,3 +141,16 @@ namespace N {
N::memset(&x1, 0, sizeof x1);
}
}
+
+namespace recursive_class {
+struct S {
+ S v;
+ // expected-error at -1{{field has incomplete type 'recursive_class::S'}}
+ // expected-note at -3{{definition of 'recursive_class::S' is not complete until the closing '}'}}
+} a;
+
+int main() {
+ __builtin_memset(&a, 0, sizeof a);
+ return 0;
+}
+}
More information about the cfe-commits
mailing list