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.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D149837 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 @@ -875,6 +875,9 @@ sizeof(A); alignof(A); + (int){1}; + (int[]){1,2,3}; + return 0; } Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -527,8 +527,13 @@ template <class Emitter> bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) { for (const Expr *Init : E->inits()) { - if (!this->visit(Init)) - return false; + if (DiscardResult) { + if (!this->discard(Init)) + return false; + } else { + if (!this->visit(Init)) + return false; + } } return true; } @@ -1024,12 +1029,16 @@ // Otherwise, use a local variable. if (T) { // For primitive types, we just visit the initializer. - return this->visit(Init); + return DiscardResult ? this->discard(Init) : this->visit(Init); } else { if (std::optional<unsigned> LocalIndex = allocateLocal(Init)) { if (!this->emitGetPtrLocal(*LocalIndex, E)) return false; - return this->visitInitializer(Init); + if (!this->visitInitializer(Init)) + return false; + if (DiscardResult) + return this->emitPopPtr(E); + return true; } }
Index: clang/test/AST/Interp/literals.cpp =================================================================== --- clang/test/AST/Interp/literals.cpp +++ clang/test/AST/Interp/literals.cpp @@ -875,6 +875,9 @@ sizeof(A); alignof(A); + (int){1}; + (int[]){1,2,3}; + return 0; } Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -527,8 +527,13 @@ template <class Emitter> bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) { for (const Expr *Init : E->inits()) { - if (!this->visit(Init)) - return false; + if (DiscardResult) { + if (!this->discard(Init)) + return false; + } else { + if (!this->visit(Init)) + return false; + } } return true; } @@ -1024,12 +1029,16 @@ // Otherwise, use a local variable. if (T) { // For primitive types, we just visit the initializer. - return this->visit(Init); + return DiscardResult ? this->discard(Init) : this->visit(Init); } else { if (std::optional<unsigned> LocalIndex = allocateLocal(Init)) { if (!this->emitGetPtrLocal(*LocalIndex, E)) return false; - return this->visitInitializer(Init); + if (!this->visitInitializer(Init)) + return false; + if (DiscardResult) + return this->emitPopPtr(E); + return true; } }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits