diff --git a/lib/SILOptimizer/Differentiation/ADContext.cpp b/lib/SILOptimizer/Differentiation/ADContext.cpp index b28acdb3ccb86..3141c5b0649c0 100644 --- a/lib/SILOptimizer/Differentiation/ADContext.cpp +++ b/lib/SILOptimizer/Differentiation/ADContext.cpp @@ -62,10 +62,8 @@ ADContext::ADContext(SILModuleTransform &transform) /// Get the source file for the given `SILFunction`. static SourceFile &getSourceFile(SILFunction *f) { - if (f->hasLocation()) - if (auto *declContext = f->getLocation().getAsDeclContext()) - if (auto *parentSourceFile = declContext->getParentSourceFile()) - return *parentSourceFile; + if (SourceFile *file = f->getSourceFile()) + return *file; for (auto *file : f->getModule().getSwiftModule()->getFiles()) if (auto *sourceFile = dyn_cast(file)) return *sourceFile;