From 5c95901a65d43dbda9cc1d901d557c24c0e05570 Mon Sep 17 00:00:00 2001 From: Aaron Eline Date: Wed, 17 Feb 2021 16:33:07 -0500 Subject: [PATCH 1/2] First draft of itypes on prototypes --- clang/lib/3C/DeclRewriter.cpp | 2 -- clang/lib/3C/ProgramInfo.cpp | 4 ---- 2 files changed, 6 deletions(-) diff --git a/clang/lib/3C/DeclRewriter.cpp b/clang/lib/3C/DeclRewriter.cpp index 8ca8d2b3a1dd..26a3cea52b00 100644 --- a/clang/lib/3C/DeclRewriter.cpp +++ b/clang/lib/3C/DeclRewriter.cpp @@ -574,8 +574,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 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); } } } From d17fd2d40f1112b3f97789fa669dcfbd1a8fbce9 Mon Sep 17 00:00:00 2001 From: Aaron Eline Date: Thu, 18 Feb 2021 15:15:35 -0500 Subject: [PATCH 2/2] Fixed issue rewriting build in prototypes --- clang/lib/3C/DeclRewriter.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/clang/lib/3C/DeclRewriter.cpp b/clang/lib/3C/DeclRewriter.cpp index 26a3cea52b00..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); @@ -616,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 = ""; @@ -644,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(); @@ -708,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);