Author: Haojian Wu
Date: 2020-06-16T12:12:10+02:00
New Revision: 28923dc2dda46610e5b6ee73bf046d2bb78a1a77

URL: 
https://github.com/llvm/llvm-project/commit/28923dc2dda46610e5b6ee73bf046d2bb78a1a77
DIFF: 
https://github.com/llvm/llvm-project/commit/28923dc2dda46610e5b6ee73bf046d2bb78a1a77.diff

LOG: [AST][RecoveryExpr] Fix a crash on a field decl with invalid type.

Summary:
The field decl (in the testcase) was still valid, which results in a
valid RecordDecl, it led to crash when performing struct layout,
and computing struct size etc.

Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81913

Added: 
    

Modified: 
    clang/lib/Sema/SemaDecl.cpp
    clang/test/Sema/invalid-member.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e6d4222d4b17..d5d946429e7d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16479,7 +16479,7 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, 
QualType T,
 
   // If we receive a broken type, recover by assuming 'int' and
   // marking this declaration as invalid.
-  if (T.isNull()) {
+  if (T.isNull() || T->containsErrors()) {
     InvalidDecl = true;
     T = Context.IntTy;
   }

diff  --git a/clang/test/Sema/invalid-member.cpp 
b/clang/test/Sema/invalid-member.cpp
index 544979980fc9..9559ead082f0 100644
--- a/clang/test/Sema/invalid-member.cpp
+++ b/clang/test/Sema/invalid-member.cpp
@@ -13,3 +13,9 @@ class Y {
 };
 // Should be able to evaluate sizeof without crashing.
 static_assert(sizeof(Y) == 1, "No valid members");
+
+class Z {
+  int array[sizeof(invalid())]; // expected-error {{use of undeclared 
identifier}}
+};
+// Should be able to evaluate sizeof without crashing.
+static_assert(sizeof(Z) == 1, "No valid members");


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to