tbaeder updated this revision to Diff 473939.
tbaeder added a comment.

Tried to find an example for an invalid declaration but couldn't even manage to 
find one :|


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

https://reviews.llvm.org/D137386

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/functions.cpp


Index: clang/test/AST/Interp/functions.cpp
===================================================================
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -84,3 +84,14 @@
   return 5;
 }
 static_assert(a() == 5, "");
+
+constexpr int invalid() {
+  // Invalid expression in visit().
+  while(huh) {}
+}
+
+constexpr void invalid2() {
+  int i = 0;
+  // Invalid expression in discard().
+  huh();
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -653,12 +653,18 @@
 }
 
 template <class Emitter> bool ByteCodeExprGen<Emitter>::discard(const Expr *E) 
{
+  if (E->containsErrors())
+    return false;
+
   OptionScope<Emitter> Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);
 }
 
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::visit(const Expr *E) {
+  if (E->containsErrors())
+    return false;
+
   OptionScope<Emitter> Scope(this, /*NewDiscardResult=*/false);
   return this->Visit(E);
 }
@@ -1226,8 +1232,10 @@
 /// We need to evaluate the initializer and return its value.
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::visitDecl(const VarDecl *VD) {
-  Optional<PrimType> VarT = classify(VD->getType());
+  if (VD->isInvalidDecl())
+    return false;
 
+  Optional<PrimType> VarT = classify(VD->getType());
   // Create and initialize the variable.
   if (!this->visitVarDecl(VD))
     return false;


Index: clang/test/AST/Interp/functions.cpp
===================================================================
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -84,3 +84,14 @@
   return 5;
 }
 static_assert(a() == 5, "");
+
+constexpr int invalid() {
+  // Invalid expression in visit().
+  while(huh) {}
+}
+
+constexpr void invalid2() {
+  int i = 0;
+  // Invalid expression in discard().
+  huh();
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -653,12 +653,18 @@
 }
 
 template <class Emitter> bool ByteCodeExprGen<Emitter>::discard(const Expr *E) {
+  if (E->containsErrors())
+    return false;
+
   OptionScope<Emitter> Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);
 }
 
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::visit(const Expr *E) {
+  if (E->containsErrors())
+    return false;
+
   OptionScope<Emitter> Scope(this, /*NewDiscardResult=*/false);
   return this->Visit(E);
 }
@@ -1226,8 +1232,10 @@
 /// We need to evaluate the initializer and return its value.
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::visitDecl(const VarDecl *VD) {
-  Optional<PrimType> VarT = classify(VD->getType());
+  if (VD->isInvalidDecl())
+    return false;
 
+  Optional<PrimType> VarT = classify(VD->getType());
   // Create and initialize the variable.
   if (!this->visitVarDecl(VD))
     return false;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to