hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: clang.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81913

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


Index: clang/test/Sema/invalid-member.cpp
===================================================================
--- clang/test/Sema/invalid-member.cpp
+++ clang/test/Sema/invalid-member.cpp
@@ -13,3 +13,9 @@
 };
 // 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");
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16479,7 +16479,7 @@
 
   // 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;
   }


Index: clang/test/Sema/invalid-member.cpp
===================================================================
--- clang/test/Sema/invalid-member.cpp
+++ clang/test/Sema/invalid-member.cpp
@@ -13,3 +13,9 @@
 };
 // 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");
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16479,7 +16479,7 @@
 
   // 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;
   }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D81913: [AST][RecoveryE... Haojian Wu via Phabricator via cfe-commits

Reply via email to