diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -2422,6 +2422,30 @@ for (auto &G : M.globals()) { if (!AliasedGlobalExclusions.count(&G) && shouldInstrumentGlobal(&G)) GlobalsToChange.push_back(&G); + StringRef offload_str = G.getSection(); + StringRef section_name = "omp_offloading_entries"; + if(G.hasInitializer() && offload_str.compare(section_name)==0) { + Constant *OldInit = G.getInitializer(); + if(OldInit->getType()->isStructTy()) { + StringRef GName = OldInit->getType()->getStructName(); + const APInt &UI = OldInit->getAggregateElement(unsigned(2))->getUniqueInteger(); + const uint64_t SizeInBytes = UI.getSExtValue(); + if(SizeInBytes != 0) { + const uint64_t RightRedzoneSize = getRedzoneSizeForGlobal(SizeInBytes); + Constant *val = ConstantInt::get(IRB.getInt64Ty(),SizeInBytes+RightRedzoneSize,true); + StructType *sttype = StructType::getTypeByName(M.getContext(),GName); + SmallVector indices(5); + indices[0] = OldInit->getAggregateElement(unsigned(0)); + indices[1] = OldInit->getAggregateElement(unsigned(1)); + indices[2] = val; + indices[3] = OldInit->getAggregateElement(unsigned(3)); + indices[4] = OldInit->getAggregateElement(unsigned(4)); + Constant *NewInit = ConstantStruct::get(sttype,indices); + NewInit->takeName(G.getInitializer()); + G.setInitializer(NewInit); + } + } + } } size_t n = GlobalsToChange.size();