================ @@ -612,6 +612,48 @@ void getAddressSanitizerParams(const Triple &TargetTriple, int LongSize, *OrShadowOffset = Mapping.OrShadowOffset; } +void removeASanIncompatibleFnAttributes(Function &F, bool RemoveWriteOnly) { + // Remove memory attributes that are invalid with ASan and HWSan. + // ASan checks read from shadow, which invalidates memory(argmem: *) + // Short granule checks on function arguments read from the argument memory + // (last byte of the granule), which invalidates writeonly. + // + // This is not only true for sanitized functions, because AttrInfer can + // infer those attributes on libc functions, which is not true if those + // are instrumented (Android) or intercepted. + // + // We might want to model ASan shadow memory more opaquely to get rid of + // this problem altogether, by hiding the shadow memory write in an + // intrinsic, essentially like in the AArch64StackTagging pass. But that's + // for another day. + + // The API is weird. `onlyReadsMemory` actually means "does not write", and + // `onlyWritesMemory` actually means "does not read". So we reconstruct + // "accesses memory" && "does not read" <=> "writes". + bool Changed = false; + if (!F.doesNotAccessMemory()) { + bool WritesMemory = !F.onlyReadsMemory(); + bool ReadsMemory = !F.onlyWritesMemory(); + if ((WritesMemory && !ReadsMemory) || F.onlyAccessesArgMemory()) { + F.removeFnAttr(Attribute::Memory); + Changed = true; + } + } + if (RemoveWriteOnly) { + for (Argument &A : F.args()) { + if (A.hasAttribute(Attribute::WriteOnly)) { + A.removeAttr(Attribute::WriteOnly); + Changed = true; + } + } + } + if (Changed) { + // nobuiltin makes sure later passes don't restore assumptions about + // the function. + F.addFnAttr(Attribute::NoBuiltin); + } +} ---------------- guy-david wrote:
I'm not completely following, can you explain what it means to "operate in terms of Memory"? https://github.com/llvm/llvm-project/pull/130495 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits