Skip to content

Commit 94115ef

Browse files
committed
Do not dereference a null callee in TBR analysis.
TBRAnalyzer::TraverseCallExpr read CE->getDirectCallee()->getNumParams() unconditionally. An indirect call -- through a function pointer, or an operator call whose operator has no resolvable FunctionDecl, as arises inside Kokkos's mdspan-based View -- has no direct callee, so this reads a null pointer. Guard the null case by conservatively marking every argument as used and stopping. No minimal standalone test accompanies this: the indirect calls clad can otherwise differentiate (function and member-function pointers) are unsupported and crash elsewhere, so a null direct callee only arises through custom-derivative machinery such as the mdspan View. The path is exercised by unittests/Kokkos/ViewAccess.
1 parent 5538c90 commit 94115ef

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

lib/Differentiator/TBRAnalyzer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,16 @@ bool TBRAnalyzer::TraverseCallExpr(clang::CallExpr* CE) {
408408
// variables passed by value/reference are used/used and changed. Analysis
409409
// could proceed to the function to analyse data flow inside it.
410410
FunctionDecl* FD = CE->getDirectCallee();
411+
// An indirect call (e.g. through a function pointer, as reached inside
412+
// Kokkos's mdspan View) has no direct callee, so the parameter walk below
413+
// would dereference a null FD. Conservatively mark every argument used.
414+
if (!FD) {
415+
setMode(Mode::kMarkingMode | Mode::kNonLinearMode);
416+
for (clang::Expr* arg : CE->arguments())
417+
TraverseStmt(arg);
418+
resetMode();
419+
return false;
420+
}
411421
// Use information about parameters assuming the analysis was performed.
412422
bool shouldAnalyzeParams = m_ModifiedParams && (m_ModifiedParams->find(FD) !=
413423
m_ModifiedParams->end());

0 commit comments

Comments
 (0)