[clang] [Reland][Clang][CodeGen][UBSan] Add more precise attributes to recoverable ubsan handlers (PR #135135)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 14 14:02:07 PDT 2025
================
@@ -3615,6 +3618,23 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
.addAttribute(llvm::Attribute::NoUnwind);
}
B.addUWTableAttr(llvm::UWTableKind::Default);
+ // Add more precise attributes to recoverable ubsan handlers for better
+ // optimizations.
+ if (CGF.CGM.getCodeGenOpts().OptimizationLevel > 0 && MayReturn) {
+ // __ubsan_handle_dynamic_type_cache_miss reads the vtable, which is also
+ // accessible by the current module.
+ if (CheckHandler != SanitizerHandler::DynamicTypeCacheMiss) {
+ llvm::MemoryEffects ME =
+ llvm::MemoryEffects::argMemOnly(llvm::ModRefInfo::Ref) |
+ llvm::MemoryEffects::inaccessibleMemOnly();
+ if (MayReadFromPtrToInt)
+ ME |= llvm::MemoryEffects::readOnly();
+ B.addMemoryAttr(ME);
+ }
+ // If the handler does not return, it must interact with the environment in
+ // an observable way.
+ B.addAttribute(llvm::Attribute::MustProgress);
----------------
efriedma-quic wrote:
I know this isn't new... but I don't think this "mustprogress" marking actually does anything useful. "mustprogress" is more a characteristic of function definitions, not calls.
https://github.com/llvm/llvm-project/pull/135135
More information about the cfe-commits
mailing list