@@ -131,10 +131,8 @@ static bool isDSAddress(const Constant *C) {
131131 return AS == AMDGPUAS::LOCAL_ADDRESS || AS == AMDGPUAS::REGION_ADDRESS;
132132}
133133
134- // / Returns true if the function requires the implicit argument be passed
135- // / regardless of the function contents.
136- static bool funcRequiresHostcallPtr (const Function &F) {
137- // Sanitizers require the hostcall buffer passed in the implicit arguments.
134+ // / Returns true if sanitizer attributes are present on a function.
135+ static bool hasSanitizerAttributes (const Function &F) {
138136 return F.hasFnAttribute (Attribute::SanitizeAddress) ||
139137 F.hasFnAttribute (Attribute::SanitizeThread) ||
140138 F.hasFnAttribute (Attribute::SanitizeMemory) ||
@@ -469,15 +467,21 @@ struct AAAMDAttributesFunction : public AAAMDAttributes {
469467
470468 // If the function requires the implicit arg pointer due to sanitizers,
471469 // assume it's needed even if explicitly marked as not requiring it.
472- const bool NeedsHostcall = funcRequiresHostcallPtr (*F);
473- if (NeedsHostcall) {
470+ // Flat scratch initialization is needed because `asan_malloc_impl`
471+ // calls introduced later in pipeline will have flat scratch accesses.
472+ // FIXME: FLAT_SCRATCH_INIT will not be required here if device-libs
473+ // implementation for `asan_malloc_impl` is updated.
474+ const bool HasSanitizerAttrs = hasSanitizerAttributes (*F);
475+ if (HasSanitizerAttrs) {
474476 removeAssumedBits (IMPLICIT_ARG_PTR);
475477 removeAssumedBits (HOSTCALL_PTR);
478+ removeAssumedBits (FLAT_SCRATCH_INIT);
476479 }
477480
478481 for (auto Attr : ImplicitAttrs) {
479- if (NeedsHostcall &&
480- (Attr.first == IMPLICIT_ARG_PTR || Attr.first == HOSTCALL_PTR))
482+ if (HasSanitizerAttrs &&
483+ (Attr.first == IMPLICIT_ARG_PTR || Attr.first == HOSTCALL_PTR ||
484+ Attr.first == FLAT_SCRATCH_INIT))
481485 continue ;
482486
483487 if (F->hasFnAttribute (Attr.second ))
0 commit comments