[PATCH] D149965: [clang][Interp] Fix tests for ignored expressions

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 5 08:12:40 PDT 2023


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

  We didn't call the function explicitly in a static_assert() statement
  and the checkPotentialConstantExpression() invocation quietly aborted
  early because of the missing initializer for A::a.
  
  Fix this by calling ignoredExprs() explicitly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149965

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


Index: clang/test/AST/Interp/literals.cpp
===================================================================
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -886,7 +886,7 @@
   struct A{ int a; };
   constexpr int ignoredExprs() {
     (void)(1 / 2);
-    A a;
+    A a{12};
     a;
     (void)a;
     (a);
@@ -906,6 +906,7 @@
 
     return 0;
   }
+  static_assert(ignoredExprs() == 0, "");
 
   /// Ignored comma expressions still have their
   /// expressions evaluated.
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -200,6 +200,8 @@
   case CK_NoOp:
   case CK_UserDefinedConversion:
   case CK_BitCast:
+    if (DiscardResult)
+      return this->discard(SubExpr);
     return this->visit(SubExpr);
 
   case CK_IntegralToBoolean:
@@ -573,6 +575,8 @@
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitUnaryExprOrTypeTraitExpr(
     const UnaryExprOrTypeTraitExpr *E) {
+  if (DiscardResult)
+    return true;
   UnaryExprOrTypeTrait Kind = E->getKind();
   ASTContext &ASTCtx = Ctx.getASTContext();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149965.519865.patch
Type: text/x-patch
Size: 1216 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230505/e0411823/attachment.bin>


More information about the cfe-commits mailing list