[PATCH] D137386: [clang][Interp] Reject invalid declarations and expressions

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 3 22:05:12 PDT 2022


tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I'm not really sure if this is the right thing to do. These expressions and declarations have been marked as containing errors before, so they can't work properly during constant evaluation anyway. But I don't see them being rejected in the current constant interpreter.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137386

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


Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -679,12 +679,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);
 }
@@ -1255,8 +1261,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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137386.473121.patch
Type: text/x-patch
Size: 1108 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221104/778005ec/attachment.bin>


More information about the cfe-commits mailing list