@@ -183,6 +183,7 @@ const char kAsanMemToShadow[] = "__asan_mem_to_shadow";
183183
184184// Accesses sizes are powers of two: 1, 2, 4, 8, 16.
185185static const size_t kNumberOfAccessSizes = 5 ;
186+ static const size_t kNumberOfAddressSpace = 5 ;
186187
187188static const uint64_t kAllocaRzSize = 32 ;
188189
@@ -897,10 +898,13 @@ struct AddressSanitizer {
897898 // These arrays is indexed by AccessIsWrite, Experiment and log2(AccessSize).
898899 FunctionCallee AsanErrorCallback[2 ][2 ][kNumberOfAccessSizes ];
899900 FunctionCallee AsanMemoryAccessCallback[2 ][2 ][kNumberOfAccessSizes ];
901+ FunctionCallee AsanMemoryAccessCallbackAS[2 ][2 ][kNumberOfAccessSizes ]
902+ [kNumberOfAddressSpace ];
900903
901904 // These arrays is indexed by AccessIsWrite and Experiment.
902905 FunctionCallee AsanErrorCallbackSized[2 ][2 ];
903906 FunctionCallee AsanMemoryAccessCallbackSized[2 ][2 ];
907+ FunctionCallee AsanMemoryAccessCallbackSizedAS[2 ][2 ][kNumberOfAddressSpace ];
904908
905909 FunctionCallee AsanMemmove, AsanMemcpy, AsanMemset;
906910 Value *LocalDynamicShadow = nullptr ;
@@ -1403,7 +1407,8 @@ static void ExtendSpirKernelArgs(Module &M, FunctionAnalysisManager &FAM) {
14031407 auto *CurF = CI->getFunction ();
14041408 Args.push_back (CurF->getArg (CurF->arg_size () - 1 ));
14051409
1406- CallInst *NewCI = CallInst::Create (NewF, Args, CI->getName (), CI);
1410+ CallInst *NewCI =
1411+ CallInst::Create (NewF, Args, CI->getName (), CI->getIterator ());
14071412 NewCI->setCallingConv (CI->getCallingConv ());
14081413 NewCI->setAttributes (CI->getAttributes ());
14091414 NewCI->setDebugLoc (CI->getDebugLoc ());
@@ -1541,7 +1546,7 @@ static bool isJointMatrixAccess(Value *V) {
15411546 for (Value *Op : CI->args ()) {
15421547 if (auto *AI = dyn_cast<AllocaInst>(Op->stripInBoundsOffsets ()))
15431548 if (auto *TargetTy = getTargetExtType (AI->getAllocatedType ()))
1544- return TargetTy->getName ().startswith (" spirv." ) &&
1549+ return TargetTy->getName ().starts_with (" spirv." ) &&
15451550 TargetTy->getName ().contains (" Matrix" );
15461551 }
15471552 }
@@ -1617,11 +1622,6 @@ void AddressSanitizer::AppendDebugInfoToArgs(Instruction *InsertBefore,
16171622 PointerType *ConstASPtrTy =
16181623 Type::getInt8Ty (C)->getPointerTo (kSpirOffloadConstantAS );
16191624
1620- // Address Space
1621- Type *PtrTy = cast<PointerType>(Addr->getType ()->getScalarType ());
1622- Args.push_back (
1623- ConstantInt::get (Type::getInt32Ty (C), PtrTy->getPointerAddressSpace ()));
1624-
16251625 // File & Line
16261626 if (Loc) {
16271627 llvm::SmallString<128 > Source = Loc->getDirectory ();
@@ -2316,10 +2316,13 @@ void AddressSanitizer::instrumentAddress(Instruction *OrigIns,
23162316 if (Exp == 0 ) {
23172317 if (TargetTriple.isSPIROrSPIRV ()) {
23182318 SmallVector<Value *, 5 > Args;
2319+ auto AS = cast<PointerType>(Addr->getType ()->getScalarType ())
2320+ ->getPointerAddressSpace ();
23192321 Args.push_back (AddrLong);
23202322 AppendDebugInfoToArgs (InsertBefore, Addr, Args);
23212323 RTCI.createRuntimeCall (
2322- IRB, AsanMemoryAccessCallback[IsWrite][0 ][AccessSizeIndex], Args);
2324+ IRB, AsanMemoryAccessCallbackAS[IsWrite][0 ][AccessSizeIndex][AS],
2325+ Args);
23232326 } else {
23242327 RTCI.createRuntimeCall (
23252328 IRB, AsanMemoryAccessCallback[IsWrite][0 ][AccessSizeIndex], AddrLong);
@@ -2398,11 +2401,13 @@ void AddressSanitizer::instrumentUnusualSizeOrAlignment(
23982401 if (Exp == 0 ) {
23992402 if (TargetTriple.isSPIROrSPIRV ()) {
24002403 SmallVector<Value *, 6 > Args;
2404+ auto AS = cast<PointerType>(Addr->getType ()->getScalarType ())
2405+ ->getPointerAddressSpace ();
24012406 Args.push_back (AddrLong);
24022407 Args.push_back (Size);
24032408 AppendDebugInfoToArgs (InsertBefore, Addr, Args);
2404- RTCI.createRuntimeCall (IRB, AsanMemoryAccessCallbackSized[IsWrite][ 0 ],
2405- Args);
2409+ RTCI.createRuntimeCall (
2410+ IRB, AsanMemoryAccessCallbackSizedAS[IsWrite][ 0 ][AS], Args);
24062411 } else {
24072412 RTCI.createRuntimeCall (IRB, AsanMemoryAccessCallbackSized[IsWrite][0 ],
24082413 {AddrLong, Size});
@@ -3280,7 +3285,6 @@ void AddressSanitizer::initializeCallbacks(const TargetLibraryInfo *TLI) {
32803285
32813286 // __asan_loadX/__asan_storeX(
32823287 // ...
3283- // int32_t as, // Address Space
32843288 // char* file,
32853289 // unsigned int line,
32863290 // char* func
@@ -3289,15 +3293,39 @@ void AddressSanitizer::initializeCallbacks(const TargetLibraryInfo *TLI) {
32893293 auto *Int8PtrTy =
32903294 Type::getInt8Ty (*C)->getPointerTo (kSpirOffloadConstantAS );
32913295
3292- Args1.push_back (Type::getInt32Ty (*C)); // address_space
32933296 Args1.push_back (Int8PtrTy); // file
32943297 Args1.push_back (Type::getInt32Ty (*C)); // line
32953298 Args1.push_back (Int8PtrTy); // func
32963299
3297- Args2.push_back (Type::getInt32Ty (*C)); // address_space
32983300 Args2.push_back (Int8PtrTy); // file
32993301 Args2.push_back (Type::getInt32Ty (*C)); // line
33003302 Args2.push_back (Int8PtrTy); // func
3303+
3304+ for (size_t AddressSpaceIndex = 0 ;
3305+ AddressSpaceIndex < kNumberOfAddressSpace ; AddressSpaceIndex++) {
3306+ AsanMemoryAccessCallbackSizedAS
3307+ [AccessIsWrite][Exp][AddressSpaceIndex] = M.getOrInsertFunction (
3308+ ClMemoryAccessCallbackPrefix + ExpStr + TypeStr + " N" +
3309+ " _as" + itostr (AddressSpaceIndex) + EndingStr,
3310+ FunctionType::get (IRB.getVoidTy (), Args2, false ), AL2);
3311+
3312+ for (size_t AccessSizeIndex = 0 ;
3313+ AccessSizeIndex < kNumberOfAccessSizes ; AccessSizeIndex++) {
3314+ const std::string Suffix = TypeStr +
3315+ itostr (1ULL << AccessSizeIndex) + " _as" +
3316+ itostr (AddressSpaceIndex);
3317+ AsanMemoryAccessCallbackAS[AccessIsWrite][Exp][AccessSizeIndex]
3318+ [AddressSpaceIndex] =
3319+ M.getOrInsertFunction (
3320+ ClMemoryAccessCallbackPrefix +
3321+ ExpStr + Suffix + EndingStr,
3322+ FunctionType::get (IRB.getVoidTy (),
3323+ Args1, false ),
3324+ AL1);
3325+ }
3326+ }
3327+
3328+ continue ;
33013329 }
33023330 AsanErrorCallbackSized[AccessIsWrite][Exp] = M.getOrInsertFunction (
33033331 kAsanReportErrorTemplate + ExpStr + TypeStr + " _n" + EndingStr,
0 commit comments