From 5d1a9d02a2096373391092791c85599381fa413c Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 21 Mar 2014 12:00:16 +0100 Subject: [PATCH] PetScan::extract_argument: avoid modifying part of pet_expr In the next commit, we will be making pet_expr objects reference counted, which means that we will no longer be able to modify part of a pet_expr without also modifying the enclosing pet_expr. Postpone the construction of the enclosing pet_expr until after the possible modification. Signed-off-by: Sven Verdoolaege --- scan.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/scan.cc b/scan.cc index 49780e3..aa2a512 100644 --- a/scan.cc +++ b/scan.cc @@ -1891,8 +1891,7 @@ struct pet_expr *PetScan::extract_argument(FunctionDecl *fd, int pos, Expr *expr) { struct pet_expr *res; - int is_addr = 0; - pet_expr *main_arg; + int is_addr = 0, is_partial = 0; Stmt::StmtClass sc; if (expr->getStmtClass() == Stmt::ImplicitCastExprClass) { @@ -1907,17 +1906,14 @@ struct pet_expr *PetScan::extract_argument(FunctionDecl *fd, int pos, } } res = extract_expr(expr); - main_arg = res; - if (is_addr) - res = pet_expr_new_unary(ctx, pet_op_address_of, res); if (!res) return NULL; sc = expr->getStmtClass(); if ((sc == Stmt::ArraySubscriptExprClass || sc == Stmt::MemberExprClass) && array_depth(expr->getType().getTypePtr()) > 0) - is_addr = 1; - if (is_addr && main_arg->type == pet_expr_access) { + is_partial = 1; + if ((is_addr || is_partial) && res->type == pet_expr_access) { ParmVarDecl *parm; if (!fd->hasPrototype()) { report_prototype_required(expr); @@ -1925,9 +1921,11 @@ struct pet_expr *PetScan::extract_argument(FunctionDecl *fd, int pos, } parm = fd->getParamDecl(pos); if (!const_base(parm->getType())) - mark_write(main_arg); + mark_write(res); } + if (is_addr) + res = pet_expr_new_unary(ctx, pet_op_address_of, res); return res; } -- 2.11.4.GIT