Index: lib/Analysis/ThreadSafetyCommon.cpp =================================================================== --- lib/Analysis/ThreadSafetyCommon.cpp +++ lib/Analysis/ThreadSafetyCommon.cpp @@ -276,18 +276,31 @@ // Function parameters require substitution and/or renaming. if (const auto *PV = dyn_cast_or_null(VD)) { - const auto *FD = - cast(PV->getDeclContext())->getCanonicalDecl(); - unsigned I = PV->getFunctionScopeIndex(); - - if (Ctx && Ctx->FunArgs && FD == Ctx->AttrDecl->getCanonicalDecl()) { - // Substitute call arguments for references to function parameters - assert(I < Ctx->NumArgs); - return translate(Ctx->FunArgs[I], Ctx->Prev); + if (isa(PV->getDeclContext())) { + unsigned I = PV->getFunctionScopeIndex(); + const auto *FD = + cast(PV->getDeclContext())->getCanonicalDecl(); + if (Ctx && Ctx->FunArgs && FD == Ctx->AttrDecl->getCanonicalDecl()) { + // Substitute call arguments for references to function parameters + assert(I < Ctx->NumArgs); + return translate(Ctx->FunArgs[I], Ctx->Prev); + } + // Map the param back to the param of the original function declaration + // for consistent comparisons. + VD = FD->getParamDecl(I); + } else { + unsigned I = PV->getFunctionScopeIndex(); + const auto *FD = + cast(PV->getDeclContext())->getCanonicalDecl(); + if (Ctx && Ctx->FunArgs && FD == Ctx->AttrDecl->getCanonicalDecl()) { + // Substitute call arguments for references to function parameters + assert(I < Ctx->NumArgs); + return translate(Ctx->FunArgs[I], Ctx->Prev); + } + // Map the param back to the param of the original function declaration + // for consistent comparisons. + VD = FD->getParamDecl(I); } - // Map the param back to the param of the original function declaration - // for consistent comparisons. - VD = FD->getParamDecl(I); } // For non-local variables, treat it as a reference to a named object.