[PATCH] D81384: [AST] Fix a clang crash on an invalid for-range statement.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 8 08:50:28 PDT 2020


This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.
Closed by commit rG936ec89e91e2: [AST] Fix a clang crash on an invalid for-range statement. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D81384?vs=269188&id=269259#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81384/new/

https://reviews.llvm.org/D81384

Files:
  clang/lib/Sema/SemaStmt.cpp
  clang/test/SemaCXX/for-range-crash.cpp


Index: clang/test/SemaCXX/for-range-crash.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/for-range-crash.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template <typename>
+class Bar {
+  Bar<int> *variables_to_modify;
+  foo() { // expected-error {{C++ requires a type specifier for all declarations}}
+    for (auto *c : *variables_to_modify)
+      delete c;
+  }
+};
Index: clang/lib/Sema/SemaStmt.cpp
===================================================================
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -2434,8 +2434,11 @@
     QualType RangeType = Range->getType();
 
     if (RequireCompleteType(RangeLoc, RangeType,
-                            diag::err_for_range_incomplete_type))
+                            diag::err_for_range_incomplete_type)) {
+      if (LoopVar->getType()->isUndeducedType())
+        LoopVar->setInvalidDecl();
       return StmtError();
+    }
 
     // Build auto __begin = begin-expr, __end = end-expr.
     // Divide by 2, since the variables are in the inner scope (loop body).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81384.269259.patch
Type: text/x-patch
Size: 1146 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200608/9403e23a/attachment.bin>


More information about the cfe-commits mailing list