Skip to content

Commit f0f3e78

Browse files
committed
Merge branch 'eyraud/123' into 'master'
clang-wrapper.cc: fix clang_getCalleeName See merge request eng/cov/gnatcoverage!262 The callee declaration can be, e.g. a parameter declaration if the call expression is a parameter callback, which is not a derived type of FunctionDecl, and thus can't be casted to it. Only deal with FunctionDecl (and FunctionTemplateDecl) type derivations and return an empty strings for the other cases. Ref: eng/cov/gnatcoverage#123
2 parents 063e627 + 7953975 commit f0f3e78

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tools/gnatcov/clang-wrapper.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,12 +487,19 @@ clang_getCalleeName (CXCursor C)
487487
return createDup (FunctionName.getAsString ().c_str ());
488488
};
489489

490-
const clang::FunctionDecl *FD;
491-
if (D->getKind () == Decl::FunctionTemplate)
492-
FD = (cast<clang::FunctionTemplateDecl> (D))->getTemplatedDecl ();
493-
else
494-
FD = cast<clang::FunctionDecl> (D);
495-
return getFunctionDeclName (FD);
490+
switch (D->getKind ())
491+
{
492+
case Decl::FunctionTemplate:
493+
return getFunctionDeclName ((cast<clang::FunctionTemplateDecl> (D))->getTemplatedDecl ());
494+
case Decl::Function:
495+
case Decl::CXXMethod:
496+
case Decl::CXXConstructor:
497+
case Decl::CXXDestructor:
498+
case Decl::CXXConversion:
499+
return getFunctionDeclName (cast<clang::FunctionDecl> (D));
500+
default:
501+
return createEmpty ();
502+
}
496503
}
497504
}
498505
return createEmpty ();

0 commit comments

Comments
 (0)