Skip to content

Commit 71f3caf

Browse files
comments
1 parent be9397f commit 71f3caf

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

clang/lib/3C/DeclRewriter.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,11 @@ bool FunctionDeclBuilder::VisitFunctionDecl(FunctionDecl *FD) {
577577
if (!Defnc->hasBody())
578578
return true;
579579

580-
// RewriteParam and RewriteReturns track if we will need to rewrite the
581-
// parameter and return type declarations on this function. There are first
580+
// RewriteParams and RewriteReturn track if we will need to rewrite the
581+
// parameter and return type declarations on this function. They are first
582582
// set to true if any changes are made to the types of the parameter and
583-
// return. If the type has changed, then it must be rewritten. There are then
584-
// some special circumstances which require rewriting the paramter or return
583+
// return. If a type has changed, then it must be rewritten. There are then
584+
// some special circumstances which require rewriting the parameter or return
585585
// even when the type as not changed.
586586
bool RewriteParams = false;
587587
bool RewriteReturn = false;
@@ -619,10 +619,15 @@ bool FunctionDeclBuilder::VisitFunctionDecl(FunctionDecl *FD) {
619619
if (FD->getReturnType()->isFunctionPointerType() && RewriteReturn)
620620
RewriteParams = true;
621621

622-
// If the function is declared with using a typedef for the function type,
623-
// then we need to rewrite parameters and the return if either would have been
622+
// If the function is declared using a typedef for the function type, then we
623+
// need to rewrite parameters and the return if either would have been
624624
// rewritten. What this does is expand the typedef to the full function type
625-
// to avoid the problem of rewriting inside the typdef.
625+
// to avoid the problem of rewriting inside the typedef.
626+
// FIXME: If issue #437 is fixed in way that preserves typedefs on function
627+
// declarations, then this conditional should be removed to enable
628+
// separate rewriting of return type and parameters on the
629+
// corresponding definition.
630+
// https://github.com/correctcomputation/checkedc-clang/issues/437
626631
if ((RewriteReturn || RewriteParams) && hasDeclWithTypedef(FD)) {
627632
RewriteParams = true;
628633
RewriteReturn = true;
@@ -747,14 +752,13 @@ bool FunctionDeclBuilder::isFunctionVisited(std::string FuncName) {
747752
return VisitedSet.find(FuncName) != VisitedSet.end();
748753
}
749754

750-
// Given a function declaration figure out if this declaration or any
751-
// other declarations for the same function are declared using a typedefed
752-
// function type.
755+
// Given a function declaration figure out if this declaration or any other
756+
// declaration of the same function is declared using a typedefed function type.
753757
bool FunctionDeclBuilder::hasDeclWithTypedef(const FunctionDecl *FD) {
754758
for (FunctionDecl *FDIter : FD->redecls()) {
755-
// If the declaration type is TypedefType, then this is definitely
756-
// declared using a typedef. This only happens when the typedefed
757-
// declaration is the first declaration of a function.
759+
// If the declaration type is TypedefType, then this is definitely declared
760+
// using a typedef. This only happens when the typedefed declaration is the
761+
// first declaration of a function.
758762
if (isa_and_nonnull<TypedefType>(FDIter->getType().getTypePtrOrNull()))
759763
return true;
760764
// Next look for a TypeDefTypeLoc. This is present on the typedefed
@@ -765,8 +769,8 @@ bool FunctionDeclBuilder::hasDeclWithTypedef(const FunctionDecl *FD) {
765769
return true;
766770
} else {
767771
// This still could possibly be a typedef type if TSI was NULL.
768-
// TypeSourceInfo can be null for implicit function declarations, so if
769-
// that implicit declaration used a typedef, we would miss it. That's fine
772+
// TypeSourceInfo is null for implicit function declarations, so if a
773+
// implicit declaration uses a typedef, it will be missed. That's fine
770774
// since an implicit declaration can't be rewritten anyways.
771775
// There might be other ways it can be null that I'm not aware of.
772776
if (Verbose) {

0 commit comments

Comments
 (0)