From: Timm Bäder Date: Fri, 21 Oct 2022 13:43:42 +0000 (+0200) Subject: [clang][Interp][NFC] Make InitField() not pop the pointer X-Git-Tag: upstream/17.0.6~28372 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9a3b969d1faa77d4c629ddb797d317579fbe0555;p=platform%2Fupstream%2Fllvm.git [clang][Interp][NFC] Make InitField() not pop the pointer This was confusing. InitElem peeks a pointer, while InitElemPop will pop the pointer. However, for fields, InitField would pop the pointer and no InitFieldPop exists. At least make InitField and InitElem behave the same. --- diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 24b5160..5362e9c 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -936,6 +936,9 @@ bool ByteCodeExprGen::visitRecordInitializer(const Expr *Initializer) { if (!this->emitInitField(*T, FieldToInit->Offset, Initializer)) return false; + + if (!this->emitPopPtr(Initializer)) + return false; } else { // Non-primitive case. Get a pointer to the field-to-initialize // on the stack and recurse into visitInitializer(). diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp index bbe4d04..81243d8 100644 --- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp @@ -114,6 +114,9 @@ bool ByteCodeStmtGen::visitFunc(const FunctionDecl *F) { if (!this->emitInitField(*T, F->Offset, InitExpr)) return false; + + if (!this->emitPopPtr(InitExpr)) + return false; } else { // Non-primitive case. Get a pointer to the field-to-initialize // on the stack and call visitInitialzer() for it. diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index c032d09..b7666745 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -735,12 +735,12 @@ bool InitThisFieldActive(InterpState &S, CodePtr OpPC, uint32_t I) { } /// 1) Pops the value from the stack -/// 2) Pops a pointer from the stack +/// 2) Peeks a pointer from the stack /// 3) Pushes the value to field I of the pointer on the stack template ::T> bool InitField(InterpState &S, CodePtr OpPC, uint32_t I) { const T &Value = S.Stk.pop(); - const Pointer &Field = S.Stk.pop().atField(I); + const Pointer &Field = S.Stk.peek().atField(I); Field.deref() = Value; Field.activate(); Field.initialize();