[AST] Fix AutoDiff crasher in optimized builds.

`getModuleScopeContext()` can produce a `ModuleDecl *` instead of a `FileUnit *`, which happens to be the case for generic-specialized derivative functions.

Resolves rdar://71191415.
This commit is contained in:
Richard Wei
2020-11-10 15:44:44 -08:00
parent a647f0fb5b
commit c9dc67d383
2 changed files with 36 additions and 1 deletions

View File

@@ -654,7 +654,9 @@ static_assert(sizeof(checkSourceLocType(&ID##Decl::getLoc)) == 2, \
// When the decl is context-free, we should get loc from source buffer.
if (!getDeclContext())
return getLocFromSource();
auto *File = cast<FileUnit>(getDeclContext()->getModuleScopeContext());
FileUnit *File = dyn_cast<FileUnit>(getDeclContext()->getModuleScopeContext());
if (!File)
return getLocFromSource();
switch(File->getKind()) {
case FileUnitKind::Source:
return getLocFromSource();