From d08a91b71eae14d973a9c50955ddac330caf9d20 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 10 Mar 2018 17:44:17 -0500 Subject: [PATCH] Fix GCC lint complaint of calling NULL->cloneTree. No functional change intended. --- src/V3Ast.cpp | 2 +- src/V3Ast.h | 4 ++++ src/V3AstNodes.h | 4 +++- src/V3Premit.cpp | 2 +- src/V3Task.cpp | 2 +- src/verilog.y | 15 +++++++++++---- 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index 5e4cb149e..ad5ce847d 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -646,7 +646,7 @@ AstNode* AstNode::cloneTreeIterList() { } AstNode* AstNode::cloneTree(bool cloneNextLink) { - if (!this) return NULL; // verilog.y relies on this + UDEBUGONLY(UASSERT(dynamic_cast(this),"this should not be NULL");); this->debugTreeChange("-cloneThs: ", __LINE__, cloneNextLink); cloneClearTree(); AstNode* newp; diff --git a/src/V3Ast.h b/src/V3Ast.h index 11edd1ea6..669539fdd 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -1312,6 +1312,8 @@ public: virtual void addBeforeStmt(AstNode* newp, AstNode* belowp); // When calling, "this" is second argument // METHODS - Iterate on a tree + static AstNode* cloneTreeNull(AstNode* nodep, bool cloneNextLink) { // Clone or return NULL if NULL + return nodep ? nodep->cloneTree(cloneNextLink) : NULL; } AstNode* cloneTree(bool cloneNextLink); bool gateTree() { return gateTreeIter(); } // Is tree isGateOptimizable? bool sameTree(const AstNode* node2p) const; // Does tree of this == node2p? @@ -1373,6 +1375,8 @@ inline void AstNRelinker::relink(AstNode* newp) { newp->AstNode::relink(this); } #define ASTNODE_BASE_FUNCS(name) \ virtual ~Ast ##name() {} \ + static Ast ##name * cloneTreeNull(Ast ##name * nodep, bool cloneNextLink) { \ + return nodep ? nodep->cloneTree(cloneNextLink) : NULL; } \ Ast ##name * cloneTree(bool cloneNext) { return static_cast(AstNode::cloneTree(cloneNext)); } \ Ast ##name * clonep() const { return static_cast(AstNode::clonep()); } diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index d4f35a8b3..3b0ecf8d1 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -30,9 +30,11 @@ #define ASTNODE_NODE_FUNCS(name) \ virtual ~Ast ##name() {} \ + virtual void accept(AstNVisitor& v) { v.visit(this); } \ virtual AstType type() const { return AstType::at ## name; } \ virtual AstNode* clone() { return new Ast ##name (*this); } \ - virtual void accept(AstNVisitor& v) { v.visit(this); } \ + static Ast ##name * cloneTreeNull(Ast ##name * nodep, bool cloneNextLink) { \ + return nodep ? nodep->cloneTree(cloneNextLink) : NULL; } \ Ast ##name * cloneTree(bool cloneNext) { return static_cast(AstNode::cloneTree(cloneNext)); } \ Ast ##name * clonep() const { return static_cast(AstNode::clonep()); } diff --git a/src/V3Premit.cpp b/src/V3Premit.cpp index 23e837ac9..d2e5a8481 100644 --- a/src/V3Premit.cpp +++ b/src/V3Premit.cpp @@ -383,7 +383,7 @@ private: } else { UINFO(4,"Autoflush "<addNextHere(new AstFFlush(nodep->fileline(), - nodep->filep()->cloneTree(true))); + AstNode::cloneTreeNull(nodep->filep(), true))); } } } diff --git a/src/V3Task.cpp b/src/V3Task.cpp index 6ed950b8e..2039e2539 100644 --- a/src/V3Task.cpp +++ b/src/V3Task.cpp @@ -361,7 +361,7 @@ private: AstNode* createInlinedFTask(AstNodeFTaskRef* refp, const string& namePrefix, AstVarScope* outvscp) { // outvscp is the variable for functions only, if NULL, it's a task if (!refp->taskp()) refp->v3fatalSrc("Unlinked?"); - AstNode* newbodysp = refp->taskp()->stmtsp()->cloneTree(true); // Maybe NULL + AstNode* newbodysp = AstNode::cloneTreeNull(refp->taskp()->stmtsp(), true); // Maybe NULL AstNode* beginp = new AstComment(refp->fileline(), (string)("Function: ")+refp->name()); if (newbodysp) beginp->addNext(newbodysp); if (debug()>=9) { beginp->dumpTreeAndNext(cout,"-newbegi:"); } diff --git a/src/verilog.y b/src/verilog.y index 484884506..908721409 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -1444,7 +1444,8 @@ member_decl_assignment: // Derived from IEEE: variable_decl_assignment // // At present we allow only packed structures/unions. So this is different from variable_decl_assignment id variable_dimensionListE { if ($2) $2->v3error("Unsupported: Unpacked array in packed struct/union"); - $$ = new AstMemberDType($1, *$1, VFlagChildDType(), GRAMMARP->m_memDTypep->cloneTree(true)); + $$ = new AstMemberDType($1, *$1, VFlagChildDType(), + AstNodeDType::cloneTreeNull(GRAMMARP->m_memDTypep, true)); PARSEP->tagNodep($$); } | id variable_dimensionListE '=' variable_declExpr @@ -2102,10 +2103,12 @@ instnameList: instnameParen: // // Must clone m_instParamp as may be comma'ed list of instances - id instRangeE '(' cellpinList ')' { $$ = new AstCell($1,*$1,GRAMMARP->m_instModule,$4, GRAMMARP->m_instParamp->cloneTree(true), + id instRangeE '(' cellpinList ')' { $$ = new AstCell($1, *$1, GRAMMARP->m_instModule, $4, + AstPin::cloneTreeNull(GRAMMARP->m_instParamp, true), GRAMMARP->scrubRange($2)); $$->trace(GRAMMARP->allTracingOn($1)); } - | id instRangeE { $$ = new AstCell($1,*$1,GRAMMARP->m_instModule,NULL,GRAMMARP->m_instParamp->cloneTree(true), + | id instRangeE { $$ = new AstCell($1, *$1, GRAMMARP->m_instModule, NULL, + AstPin::cloneTreeNull(GRAMMARP->m_instParamp, true), GRAMMARP->scrubRange($2)); $$->trace(GRAMMARP->allTracingOn($1)); } //UNSUP instRangeE '(' cellpinList ')' { UNSUP } // UDP @@ -2375,7 +2378,11 @@ statement_item: // IEEE: statement_item // // for's first ';' is in for_initalization | yFOR '(' for_initialization expr ';' for_stepE ')' stmtBlock { $$ = new AstBegin($1,"",$3); $3->addNext(new AstWhile($1, $4,$8,$6)); } - | yDO stmtBlock yWHILE '(' expr ')' ';' { $$ = $2->cloneTree(true); $$->addNext(new AstWhile($1,$5,$2));} + | yDO stmtBlock yWHILE '(' expr ')' ';' { if ($2) { + $$ = $2->cloneTree(true); + $$->addNext(new AstWhile($1,$5,$2)); + } + else $$ = new AstWhile($1,$5,NULL); } // // IEEE says array_identifier here, but dotted accepted in VMM and 1800-2009 | yFOREACH '(' idClassForeach '[' loop_variables ']' ')' stmtBlock { $$ = new AstForeach($1,$3,$5,$8); } //