Skip to content

First draft of itypes on prototypes #435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions clang/lib/3C/DeclRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -710,7 +712,8 @@ FunctionDeclBuilder::buildDeclVar(PVConstraint *IntCV, PVConstraint *ExtCV,
// strings are taken unchanged from the original source.
if (isa<ParmVarDecl>(Decl)) {
Type = getSourceText(Decl->getSourceRange(), *Context);
IType = "";
IType = getExistingIType(ExtCV);
IType += ABRewriter.getBoundsString(ExtCV, Decl, !IType.empty());
} else {
Type = ExtCV->getOriginalTy() + " ";
IType = getExistingIType(ExtCV);
Expand Down
4 changes: 0 additions & 4 deletions clang/lib/3C/ProgramInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down