@@ -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 ());
@@ -1547,7 +1552,7 @@ static bool isJointMatrixAccess(Value *V) {
15471552 for (Value *Op : CI->args ()) {
15481553 if (auto *AI = dyn_cast<AllocaInst>(Op->stripInBoundsOffsets ()))
15491554 if (auto *TargetTy = getTargetExtType (AI->getAllocatedType ()))
1550- return TargetTy->getName ().startswith (" spirv." ) &&
1555+ return TargetTy->getName ().starts_with (" spirv." ) &&
15511556 TargetTy->getName ().contains (" Matrix" );
15521557 }
15531558 }
@@ -1623,11 +1628,6 @@ void AddressSanitizer::AppendDebugInfoToArgs(Instruction *InsertBefore,
16231628 PointerType *ConstASPtrTy =
16241629 Type::getInt8Ty (C)->getPointerTo (kSpirOffloadConstantAS );
16251630
1626- // Address Space
1627- Type *PtrTy = cast<PointerType>(Addr->getType ()->getScalarType ());
1628- Args.push_back (
1629- ConstantInt::get (Type::getInt32Ty (C), PtrTy->getPointerAddressSpace ()));
1630-
16311631 // File & Line
16321632 if (Loc) {
16331633 llvm::SmallString<128 > Source = Loc->getDirectory ();
@@ -2322,10 +2322,13 @@ void AddressSanitizer::instrumentAddress(Instruction *OrigIns,
23222322 if (Exp == 0 ) {
23232323 if (TargetTriple.isSPIROrSPIRV ()) {
23242324 SmallVector<Value *, 5 > Args;
2325+ auto AS = cast<PointerType>(Addr->getType ()->getScalarType ())
2326+ ->getPointerAddressSpace ();
23252327 Args.push_back (AddrLong);
23262328 AppendDebugInfoToArgs (InsertBefore, Addr, Args);
23272329 RTCI.createRuntimeCall (
2328- IRB, AsanMemoryAccessCallback[IsWrite][0 ][AccessSizeIndex], Args);
2330+ IRB, AsanMemoryAccessCallbackAS[IsWrite][0 ][AccessSizeIndex][AS],
2331+ Args);
23292332 } else {
23302333 RTCI.createRuntimeCall (
23312334 IRB, AsanMemoryAccessCallback[IsWrite][0 ][AccessSizeIndex], AddrLong);
@@ -2404,11 +2407,13 @@ void AddressSanitizer::instrumentUnusualSizeOrAlignment(
24042407 if (Exp == 0 ) {
24052408 if (TargetTriple.isSPIROrSPIRV ()) {
24062409 SmallVector<Value *, 6 > Args;
2410+ auto AS = cast<PointerType>(Addr->getType ()->getScalarType ())
2411+ ->getPointerAddressSpace ();
24072412 Args.push_back (AddrLong);
24082413 Args.push_back (Size);
24092414 AppendDebugInfoToArgs (InsertBefore, Addr, Args);
2410- RTCI.createRuntimeCall (IRB, AsanMemoryAccessCallbackSized[IsWrite][ 0 ],
2411- Args);
2415+ RTCI.createRuntimeCall (
2416+ IRB, AsanMemoryAccessCallbackSizedAS[IsWrite][ 0 ][AS], Args);
24122417 } else {
24132418 RTCI.createRuntimeCall (IRB, AsanMemoryAccessCallbackSized[IsWrite][0 ],
24142419 {AddrLong, Size});
@@ -3286,7 +3291,6 @@ void AddressSanitizer::initializeCallbacks(const TargetLibraryInfo *TLI) {
32863291
32873292 // __asan_loadX/__asan_storeX(
32883293 // ...
3289- // int32_t as, // Address Space
32903294 // char* file,
32913295 // unsigned int line,
32923296 // char* func
@@ -3295,15 +3299,39 @@ void AddressSanitizer::initializeCallbacks(const TargetLibraryInfo *TLI) {
32953299 auto *Int8PtrTy =
32963300 Type::getInt8Ty (*C)->getPointerTo (kSpirOffloadConstantAS );
32973301
3298- Args1.push_back (Type::getInt32Ty (*C)); // address_space
32993302 Args1.push_back (Int8PtrTy); // file
33003303 Args1.push_back (Type::getInt32Ty (*C)); // line
33013304 Args1.push_back (Int8PtrTy); // func
33023305
3303- Args2.push_back (Type::getInt32Ty (*C)); // address_space
33043306 Args2.push_back (Int8PtrTy); // file
33053307 Args2.push_back (Type::getInt32Ty (*C)); // line
33063308 Args2.push_back (Int8PtrTy); // func
3309+
3310+ for (size_t AddressSpaceIndex = 0 ;
3311+ AddressSpaceIndex < kNumberOfAddressSpace ; AddressSpaceIndex++) {
3312+ AsanMemoryAccessCallbackSizedAS
3313+ [AccessIsWrite][Exp][AddressSpaceIndex] = M.getOrInsertFunction (
3314+ ClMemoryAccessCallbackPrefix + ExpStr + TypeStr + " N" +
3315+ " _as" + itostr (AddressSpaceIndex) + EndingStr,
3316+ FunctionType::get (IRB.getVoidTy (), Args2, false ), AL2);
3317+
3318+ for (size_t AccessSizeIndex = 0 ;
3319+ AccessSizeIndex < kNumberOfAccessSizes ; AccessSizeIndex++) {
3320+ const std::string Suffix = TypeStr +
3321+ itostr (1ULL << AccessSizeIndex) + " _as" +
3322+ itostr (AddressSpaceIndex);
3323+ AsanMemoryAccessCallbackAS[AccessIsWrite][Exp][AccessSizeIndex]
3324+ [AddressSpaceIndex] =
3325+ M.getOrInsertFunction (
3326+ ClMemoryAccessCallbackPrefix +
3327+ ExpStr + Suffix + EndingStr,
3328+ FunctionType::get (IRB.getVoidTy (),
3329+ Args1, false ),
3330+ AL1);
3331+ }
3332+ }
3333+
3334+ continue ;
33073335 }
33083336 AsanErrorCallbackSized[AccessIsWrite][Exp] = M.getOrInsertFunction (
33093337 kAsanReportErrorTemplate + ExpStr + TypeStr + " _n" + EndingStr,
0 commit comments