diff --git a/clang/lib/3C/DeclRewriter.cpp b/clang/lib/3C/DeclRewriter.cpp index 8ca8d2b3a1dd..0be76f8accfd 100644 --- a/clang/lib/3C/DeclRewriter.cpp +++ b/clang/lib/3C/DeclRewriter.cpp @@ -158,6 +158,7 @@ void DeclRewriter::rewriteDecls(ASTContext &Context, ProgramInfo &Info, } void DeclRewriter::rewrite(RSet &ToRewrite) { + auto Len = ToRewrite.size(); for (auto *const N : ToRewrite) { assert(N->getDecl() != nullptr); @@ -574,8 +575,6 @@ bool FunctionDeclBuilder::VisitFunctionDecl(FunctionDecl *FD) { // If this is an external function, there is no need to rewrite the // declaration. We cannot change the signature of external functions. - if (!Defnc->hasBody()) - return true; // DidAnyParams tracks if we have made any changes to the parameters for this // declarations. If no changes are made, then there is no need to rewrite the @@ -618,6 +617,7 @@ bool FunctionDeclBuilder::VisitFunctionDecl(FunctionDecl *FD) { if (FD->getReturnType()->isFunctionPointerType() && RewriteReturn) RewriteParams = true; + // Combine parameter and return variables rewritings into a single rewriting // for the entire function declaration. std::string NewSig = ""; @@ -646,8 +646,10 @@ bool FunctionDeclBuilder::VisitFunctionDecl(FunctionDecl *FD) { // Add new declarations to RewriteThese if it has changed if (RewriteReturn || RewriteParams) { for (auto *const RD : Definition->redecls()) - RewriteThese.insert(new FunctionDeclReplacement(RD, NewSig, RewriteReturn, - RewriteParams)); + if (!RD->isImplicit()) + RewriteThese.insert(new FunctionDeclReplacement(RD, NewSig, + RewriteReturn, + RewriteParams)); // Save the modified function signature. if (FD->isStatic()) { auto FileName = PersistentSourceLoc::mkPSL(FD, *Context).getFileName(); @@ -710,7 +712,8 @@ FunctionDeclBuilder::buildDeclVar(PVConstraint *IntCV, PVConstraint *ExtCV, // strings are taken unchanged from the original source. if (isa(Decl)) { Type = getSourceText(Decl->getSourceRange(), *Context); - IType = ""; + IType = getExistingIType(ExtCV); + IType += ABRewriter.getBoundsString(ExtCV, Decl, !IType.empty()); } else { Type = ExtCV->getOriginalTy() + " "; IType = getExistingIType(ExtCV); diff --git a/clang/lib/3C/ProgramInfo.cpp b/clang/lib/3C/ProgramInfo.cpp index 5d55d7ac79dd..f2ee31b86679 100644 --- a/clang/lib/3C/ProgramInfo.cpp +++ b/clang/lib/3C/ProgramInfo.cpp @@ -335,12 +335,8 @@ bool ProgramInfo::link() { "Unchecked pointer in parameter or return of external function " + FuncName; G->getInternalReturn()->constrainToWild(CS, Rsn); - if (!G->getExternalReturn()->getIsGeneric()) - G->getExternalReturn()->constrainToWild(CS, Rsn); for (unsigned I = 0; I < G->numParams(); I++) { G->getInternalParam(I)->constrainToWild(CS, Rsn); - if (!G->getExternalParam(I)->getIsGeneric()) - G->getExternalParam(I)->constrainToWild(CS, Rsn); } } }