Skip to content

Commit

Permalink
Merge pull request #580 from jjwilke/fix-fxn-pragma-skip
Browse files Browse the repository at this point in the history
Fix function skip bug for pragmas on FunctionDecls
  • Loading branch information
jjwilke authored Sep 29, 2020
2 parents 02965bc + adee708 commit 39eaf74
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
21 changes: 5 additions & 16 deletions bin/clang/astConsumers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,13 @@ SkeletonASTConsumer::HandleTopLevelDecl(DeclGroupRef DR)
{
for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b){
Decl* d = *b;
switch(d->getKind()){
case Decl::Function: {
FunctionDecl* fd = cast<FunctionDecl>(d);
//the function decl will have its body filled in later
//possibly - we need to make sure to only add the function once
if (fd->isThisDeclarationADefinition()){
//also, we only really care about the definition anyway
allTopLevelDecls_.push_back(d);
}
if (isNullWhitelisted(fd->getNameAsString())){
CompilerGlobals::astNodeMetadata.nullSafeFunctions[fd] = nullptr;
}
if (d->getKind() == Decl::Function){
FunctionDecl* fd = cast<FunctionDecl>(d);
if (isNullWhitelisted(fd->getNameAsString())){
CompilerGlobals::astNodeMetadata.nullSafeFunctions[fd] = nullptr;
}
break;
default:
allTopLevelDecls_.push_back(d);
break;
}
allTopLevelDecls_.push_back(d);
}
return true;
}
Expand Down
20 changes: 14 additions & 6 deletions bin/clang/astVisitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,9 @@ SkeletonASTVisitor::TraverseCallExpr(CallExpr* expr, DataRecursionQueue* /*queu
PragmaActivateGuard pag(expr, this);
if (pag.skipVisit()) return true;

//first go into the call expression to see if we should even keep it
//we might get a delete exception, in which case we should skip traversal
//if we got here, we are safe to modify the function name
if (CompilerGlobals::modeActive(SKELETONIZE | SHADOWIZE)) {
Expr* fxn = getUnderlyingExpr(const_cast<Expr*>(expr->getCallee()));
if (fxn->getStmtClass() == Stmt::DeclRefExprClass){
Expand Down Expand Up @@ -1939,6 +1942,9 @@ SkeletonASTVisitor::traverseFunctionBody(clang::Stmt* s)
bool
SkeletonASTVisitor::TraverseFunctionDecl(clang::FunctionDecl* D)
{
if (!D->isThisDeclarationADefinition()){
return true;
}
if (D->isMain() && CompilerGlobals::refactorMain){
replaceMain(D);
} else if (D->isTemplateInstantiation()
Expand Down Expand Up @@ -2399,7 +2405,6 @@ SkeletonASTVisitor::TraverseArraySubscriptExpr(ArraySubscriptExpr* expr, DataRec
PushGuard<Expr*> pg(activeDerefs_, expr);
TraverseStmt(expr->getBase());
TraverseStmt(expr->getIdx());

return true;
}

Expand Down Expand Up @@ -2443,7 +2448,7 @@ SkeletonASTVisitor::TraverseDecl(Decl *D)
PragmaActivateGuard pag(D, this);
if (pag.skipVisit()) return true;

RecursiveASTVisitor<SkeletonASTVisitor>::TraverseDecl(D);
return RecursiveASTVisitor<SkeletonASTVisitor>::TraverseDecl(D);
} catch (DeclDeleteException& e) {
if (e.deleted != D) throw e;
}
Expand Down Expand Up @@ -2697,16 +2702,19 @@ bool
FirstPassASTVisitor::TraverseFunctionDecl(FunctionDecl *fd, DataRecursionQueue* /*queue*/)
{
PushGuard<FunctionDecl*> pg(CompilerGlobals::astContextLists.enclosingFunctionDecls, fd);
Parent::TraverseFunctionDecl(fd);
return true;
PragmaActivateGuard pag(fd, this, true/*always do first pass pragmas*/);
if (fd->isThisDeclarationADefinition()){
return Parent::TraverseFunctionDecl(fd);
} else {
return true;
}
}

bool
FirstPassASTVisitor::TraverseCompoundStmt(CompoundStmt* cs, DataRecursionQueue* /*queue*/)
{
PushGuard<CompoundStmt*> pg(CompilerGlobals::astContextLists.compoundStmtBlocks, cs);
Parent::TraverseCompoundStmt(cs);
return true;
return Parent::TraverseCompoundStmt(cs);
}

FirstPassASTVisitor::FirstPassASTVisitor(SSTPragmaList& prgs) :
Expand Down
3 changes: 3 additions & 0 deletions bin/clang/pragmas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ static void tokenToString(const Token& tok, std::ostream& os)
case tok::kw_true:
os << "true";
break;
case tok::kw_void:
os << "void";
break;
case tok::kw_false:
os << "false";
break;
Expand Down
4 changes: 0 additions & 4 deletions sstmac/replacements/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,10 @@ extern "C" {
#pragma clang diagnostic ignored "-Wunknown-pragmas"
#endif

#if defined(__clang__) // Only include S2S things if clang
#pragma sst null_ptr safe
#endif
void* sstmac_memset(void* ptr, int value, unsigned long sz);

#if defined(__clang__) // Only include S2S things if clang
#pragma sst null_ptr safe
#endif
void* sstmac_memcpy(void* dst, const void* src, unsigned long sz);

#if defined(__clang__) // Add back the warnings
Expand Down

0 comments on commit 39eaf74

Please sign in to comment.