7474#include " llvm/TargetParser/Triple.h"
7575#include " llvm/Transforms/Instrumentation/AddressSanitizerCommon.h"
7676#include " llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
77- #include " llvm/Transforms/Instrumentation/SanitizerCommonUtils .h"
77+ #include " llvm/Transforms/Instrumentation/SPIRVSanitizerCommonUtils .h"
7878#include " llvm/Transforms/Utils/ASanStackFrameLayout.h"
7979#include " llvm/Transforms/Utils/BasicBlockUtils.h"
8080#include " llvm/Transforms/Utils/Instrumentation.h"
@@ -867,7 +867,7 @@ struct AddressSanitizer {
867867 void instrumentMemIntrinsic (MemIntrinsic *MI, RuntimeCallInserter &RTCI);
868868 Value *memToShadow (
869869 Value *Shadow, IRBuilder<> &IRB,
870- uint32_t AddressSpace = SanitizerCommonUtils ::kSpirOffloadPrivateAS );
870+ uint32_t AddressSpace = SPIRVSanitizerCommonUtils ::kSpirOffloadPrivateAS );
871871 bool suppressInstrumentationSiteForDebug (int &Instrumented);
872872 bool instrumentFunction (Function &F, const TargetLibraryInfo *TLI);
873873 bool maybeInsertAsanInitAtFunctionEntry (Function &F);
@@ -1397,9 +1397,9 @@ static void ExtendSpirKernelArgs(Module &M, FunctionAnalysisManager &FAM,
13971397 SpirFixupKernels.emplace_back (&F);
13981398
13991399 auto KernelName = F.getName ();
1400- auto *KernelNameGV =
1401- GetOrCreateGlobalString ( M, " __asan_kernel" , KernelName,
1402- SanitizerCommonUtils ::kSpirOffloadConstantAS );
1400+ auto *KernelNameGV = GetOrCreateGlobalString (
1401+ M, " __asan_kernel" , KernelName,
1402+ SPIRVSanitizerCommonUtils ::kSpirOffloadConstantAS );
14031403 SpirKernelsMetadata.emplace_back (ConstantStruct::get (
14041404 StructTy, ConstantExpr::getPointerCast (KernelNameGV, IntptrTy),
14051405 ConstantInt::get (IntptrTy, KernelName.size ())));
@@ -1435,7 +1435,7 @@ static void ExtendSpirKernelArgs(Module &M, FunctionAnalysisManager &FAM,
14351435
14361436 // New argument: uintptr_t as(1)*, which is allocated in shared USM buffer
14371437 Types.push_back (llvm::PointerType::get (
1438- IntptrTy, SanitizerCommonUtils ::kSpirOffloadGlobalAS ));
1438+ IntptrTy, SPIRVSanitizerCommonUtils ::kSpirOffloadGlobalAS ));
14391439
14401440 FunctionType *NewFTy = FunctionType::get (F->getReturnType (), Types, false );
14411441
@@ -1495,7 +1495,7 @@ static void ExtendSpirKernelArgs(Module &M, FunctionAnalysisManager &FAM,
14951495
14961496 FixupMetadata (" kernel_arg_addr_space" ,
14971497 ConstantAsMetadata::get (Builder.getInt32 (
1498- SanitizerCommonUtils ::kSpirOffloadGlobalAS )));
1498+ SPIRVSanitizerCommonUtils ::kSpirOffloadGlobalAS )));
14991499 FixupMetadata (" kernel_arg_access_qual" ,
15001500 MDString::get (M.getContext (), " read_write" ));
15011501 FixupMetadata (" kernel_arg_type" , MDString::get (M.getContext (), " void*" ));
@@ -1681,34 +1681,34 @@ static bool isUnsupportedSPIRAccess(Value *Addr, Instruction *Inst) {
16811681 // Ignore load/store for target ext type since we can't know exactly what size
16821682 // it is.
16831683 if (auto *SI = dyn_cast<StoreInst>(Inst))
1684- if (SanitizerCommonUtils ::getTargetExtType (
1684+ if (SPIRVSanitizerCommonUtils ::getTargetExtType (
16851685 SI->getValueOperand ()->getType ()) ||
1686- SanitizerCommonUtils ::isJointMatrixAccess (SI->getPointerOperand ()))
1686+ SPIRVSanitizerCommonUtils ::isJointMatrixAccess (SI->getPointerOperand ()))
16871687 return true ;
16881688
16891689 if (auto *LI = dyn_cast<LoadInst>(Inst))
1690- if (SanitizerCommonUtils ::getTargetExtType (Inst->getType ()) ||
1691- SanitizerCommonUtils ::isJointMatrixAccess (LI->getPointerOperand ()))
1690+ if (SPIRVSanitizerCommonUtils ::getTargetExtType (Inst->getType ()) ||
1691+ SPIRVSanitizerCommonUtils ::isJointMatrixAccess (LI->getPointerOperand ()))
16921692 return true ;
16931693
16941694 Type *PtrTy = cast<PointerType>(Addr->getType ()->getScalarType ());
16951695 switch (PtrTy->getPointerAddressSpace ()) {
1696- case SanitizerCommonUtils ::kSpirOffloadPrivateAS : {
1696+ case SPIRVSanitizerCommonUtils ::kSpirOffloadPrivateAS : {
16971697 if (!ClSpirOffloadPrivates)
16981698 return true ;
16991699 // Skip kernel arguments
17001700 return Inst->getFunction ()->getCallingConv () == CallingConv::SPIR_KERNEL &&
17011701 isa<Argument>(Addr);
17021702 }
1703- case SanitizerCommonUtils ::kSpirOffloadGlobalAS : {
1703+ case SPIRVSanitizerCommonUtils ::kSpirOffloadGlobalAS : {
17041704 return !ClSpirOffloadGlobals;
17051705 }
1706- case SanitizerCommonUtils ::kSpirOffloadLocalAS : {
1706+ case SPIRVSanitizerCommonUtils ::kSpirOffloadLocalAS : {
17071707 if (!ClSpirOffloadLocals)
17081708 return true ;
17091709 return Addr->getName ().starts_with (" __Asan" );
17101710 }
1711- case SanitizerCommonUtils ::kSpirOffloadGenericAS : {
1711+ case SPIRVSanitizerCommonUtils ::kSpirOffloadGenericAS : {
17121712 return !ClSpirOffloadGenerics;
17131713 }
17141714 }
@@ -1724,15 +1724,15 @@ void AddressSanitizer::AppendDebugInfoToArgs(Instruction *InsertBefore,
17241724
17251725 // SPIR constant address space
17261726 PointerType *ConstASPtrTy = llvm::PointerType::get (
1727- Type::getInt8Ty (C), SanitizerCommonUtils ::kSpirOffloadConstantAS );
1727+ Type::getInt8Ty (C), SPIRVSanitizerCommonUtils ::kSpirOffloadConstantAS );
17281728
17291729 // File & Line
17301730 if (Loc) {
17311731 llvm::SmallString<128 > Source = Loc->getDirectory ();
17321732 sys::path::append (Source, Loc->getFilename ());
1733- auto *FileNameGV =
1734- GetOrCreateGlobalString ( *M, " __asan_file" , Source,
1735- SanitizerCommonUtils ::kSpirOffloadConstantAS );
1733+ auto *FileNameGV = GetOrCreateGlobalString (
1734+ *M, " __asan_file" , Source,
1735+ SPIRVSanitizerCommonUtils ::kSpirOffloadConstantAS );
17361736 Args.push_back (ConstantExpr::getPointerCast (FileNameGV, ConstASPtrTy));
17371737 Args.push_back (ConstantInt::get (Type::getInt32Ty (C), Loc.getLine ()));
17381738 } else {
@@ -1742,9 +1742,9 @@ void AddressSanitizer::AppendDebugInfoToArgs(Instruction *InsertBefore,
17421742
17431743 // Function
17441744 auto FuncName = InsertBefore->getFunction ()->getName ();
1745- auto *FuncNameGV =
1746- GetOrCreateGlobalString ( *M, " __asan_func" , demangle (FuncName),
1747- SanitizerCommonUtils ::kSpirOffloadConstantAS );
1745+ auto *FuncNameGV = GetOrCreateGlobalString (
1746+ *M, " __asan_func" , demangle (FuncName),
1747+ SPIRVSanitizerCommonUtils ::kSpirOffloadConstantAS );
17481748 Args.push_back (ConstantExpr::getPointerCast (FuncNameGV, ConstASPtrTy));
17491749}
17501750
@@ -1781,7 +1781,7 @@ bool AddressSanitizer::instrumentSyclDynamicLocalMemory(
17811781 for (auto &Arg : F.args ()) {
17821782 Type *PtrTy = dyn_cast<PointerType>(Arg.getType ()->getScalarType ());
17831783 if (PtrTy && PtrTy->getPointerAddressSpace () ==
1784- SanitizerCommonUtils ::kSpirOffloadLocalAS )
1784+ SPIRVSanitizerCommonUtils ::kSpirOffloadLocalAS )
17851785 LocalArgs.push_back (&Arg);
17861786 }
17871787
@@ -1826,9 +1826,10 @@ void AddressSanitizer::instrumentInitAsanLaunchInfo(
18261826 // FIXME: if the initial value of "__AsanLaunchInfo" is zero, we'll not need
18271827 // this step
18281828 initializeCallbacks (TLI);
1829- IRB.CreateStore (ConstantPointerNull::get (llvm::PointerType::get (
1830- IntptrTy, SanitizerCommonUtils::kSpirOffloadGlobalAS )),
1831- AsanLaunchInfo);
1829+ IRB.CreateStore (
1830+ ConstantPointerNull::get (llvm::PointerType::get (
1831+ IntptrTy, SPIRVSanitizerCommonUtils::kSpirOffloadGlobalAS )),
1832+ AsanLaunchInfo);
18321833}
18331834
18341835// Instrument memset/memmove/memcpy
@@ -1874,7 +1875,7 @@ bool AddressSanitizer::isInterestingAlloca(const AllocaInst &AI) {
18741875 !(SSGI && SSGI->isSafe (AI)) &&
18751876 // ignore alloc contains target ext type since we can't know exactly what
18761877 // size it is.
1877- !SanitizerCommonUtils ::getTargetExtType (AI.getAllocatedType ()));
1878+ !SPIRVSanitizerCommonUtils ::getTargetExtType (AI.getAllocatedType ()));
18781879
18791880 It->second = IsInteresting;
18801881 return IsInteresting;
@@ -2848,7 +2849,7 @@ void ModuleAddressSanitizer::instrumentDeviceGlobal(IRBuilder<> &IRB) {
28482849 SmallVector<Constant *, 8 > DeviceGlobalMetadata;
28492850
28502851 Type *IntptrTy = M.getDataLayout ().getIntPtrType (
2851- *C, SanitizerCommonUtils ::kSpirOffloadGlobalAS );
2852+ *C, SPIRVSanitizerCommonUtils ::kSpirOffloadGlobalAS );
28522853
28532854 // Device global meta data is described by a structure
28542855 // size_t device_global_size
@@ -3607,7 +3608,8 @@ void AddressSanitizer::initializeCallbacks(const TargetLibraryInfo *TLI) {
36073608 // )
36083609 if (TargetTriple.isSPIROrSPIRV ()) {
36093610 auto *Int8PtrTy = llvm::PointerType::get (
3610- Type::getInt8Ty (*C), SanitizerCommonUtils::kSpirOffloadConstantAS );
3611+ Type::getInt8Ty (*C),
3612+ SPIRVSanitizerCommonUtils::kSpirOffloadConstantAS );
36113613
36123614 Args1.push_back (Int8PtrTy); // file
36133615 Args1.push_back (Type::getInt32Ty (*C)); // line
@@ -3709,15 +3711,15 @@ void AddressSanitizer::initializeCallbacks(const TargetLibraryInfo *TLI) {
37093711 AsanLaunchInfo = M.getOrInsertGlobal (
37103712 " __AsanLaunchInfo" ,
37113713 llvm::PointerType::get (IntptrTy,
3712- SanitizerCommonUtils ::kSpirOffloadGlobalAS ),
3714+ SPIRVSanitizerCommonUtils ::kSpirOffloadGlobalAS ),
37133715 [&] {
37143716 return new GlobalVariable (
37153717 M,
37163718 llvm::PointerType::get (
3717- IntptrTy, SanitizerCommonUtils ::kSpirOffloadGlobalAS ),
3719+ IntptrTy, SPIRVSanitizerCommonUtils ::kSpirOffloadGlobalAS ),
37183720 false , GlobalVariable::ExternalLinkage, nullptr ,
37193721 " __AsanLaunchInfo" , nullptr , GlobalVariable::NotThreadLocal,
3720- SanitizerCommonUtils ::kSpirOffloadLocalAS );
3722+ SPIRVSanitizerCommonUtils ::kSpirOffloadLocalAS );
37213723 });
37223724
37233725 AsanMemToShadow = M.getOrInsertFunction (kAsanMemToShadow , IntptrTy,
@@ -4503,7 +4505,7 @@ void FunctionStackPoisoner::processStaticAllocas() {
45034505
45044506 // Poison the stack red zones at the entry.
45054507 Value *ShadowBase = ASan.memToShadow (
4506- LocalStackBase, IRB, SanitizerCommonUtils ::kSpirOffloadPrivateAS );
4508+ LocalStackBase, IRB, SPIRVSanitizerCommonUtils ::kSpirOffloadPrivateAS );
45074509 // As mask we must use most poisoned case: red zones and after scope.
45084510 // As bytes we can use either the same or just red zones only.
45094511 copyToShadow (ShadowAfterScope, ShadowAfterScope, IRB, ShadowBase,
0 commit comments