@@ -577,11 +577,11 @@ bool FunctionDeclBuilder::VisitFunctionDecl(FunctionDecl *FD) {
577
577
if (!Defnc->hasBody ())
578
578
return true ;
579
579
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
582
582
// 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
585
585
// even when the type as not changed.
586
586
bool RewriteParams = false ;
587
587
bool RewriteReturn = false ;
@@ -619,10 +619,15 @@ bool FunctionDeclBuilder::VisitFunctionDecl(FunctionDecl *FD) {
619
619
if (FD->getReturnType ()->isFunctionPointerType () && RewriteReturn)
620
620
RewriteParams = true ;
621
621
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
624
624
// 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
626
631
if ((RewriteReturn || RewriteParams) && hasDeclWithTypedef (FD)) {
627
632
RewriteParams = true ;
628
633
RewriteReturn = true ;
@@ -747,14 +752,13 @@ bool FunctionDeclBuilder::isFunctionVisited(std::string FuncName) {
747
752
return VisitedSet.find (FuncName) != VisitedSet.end ();
748
753
}
749
754
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.
753
757
bool FunctionDeclBuilder::hasDeclWithTypedef (const FunctionDecl *FD) {
754
758
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.
758
762
if (isa_and_nonnull<TypedefType>(FDIter->getType ().getTypePtrOrNull ()))
759
763
return true ;
760
764
// Next look for a TypeDefTypeLoc. This is present on the typedefed
@@ -765,8 +769,8 @@ bool FunctionDeclBuilder::hasDeclWithTypedef(const FunctionDecl *FD) {
765
769
return true ;
766
770
} else {
767
771
// 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
770
774
// since an implicit declaration can't be rewritten anyways.
771
775
// There might be other ways it can be null that I'm not aware of.
772
776
if (Verbose) {
0 commit comments