ztong0001 updated this revision to Diff 411040. ztong0001 edited the summary of this revision. ztong0001 added a comment.
update patch and description as suggested by Marco Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D119816/new/ https://reviews.llvm.org/D119816 Files: clang/lib/CodeGen/CodeGenFunction.cpp clang/test/CodeGen/sanitize-coverage.c llvm/bindings/go/llvm/ir_test.go llvm/docs/BitCodeFormat.rst llvm/docs/LangRef.rst llvm/include/llvm/AsmParser/LLToken.h llvm/include/llvm/Bitcode/LLVMBitCodes.h llvm/include/llvm/IR/Attributes.td llvm/lib/AsmParser/LLLexer.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp llvm/lib/Transforms/Utils/CodeExtractor.cpp llvm/test/Bitcode/attributes.ll llvm/test/Bitcode/compatibility.ll llvm/utils/emacs/llvm-mode.el llvm/utils/llvm.grm llvm/utils/vim/syntax/llvm.vim llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml
Index: llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml =================================================================== --- llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml +++ llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml @@ -238,6 +238,7 @@ \\bnosync\\b|\ \\bnoundef\\b|\ \\bnounwind\\b|\ + \\bnosanitize_bounds\\b|\ \\bnosanitize_coverage\\b|\ \\bnull_pointer_is_valid\\b|\ \\boptforfuzzing\\b|\ Index: llvm/utils/vim/syntax/llvm.vim =================================================================== --- llvm/utils/vim/syntax/llvm.vim +++ llvm/utils/vim/syntax/llvm.vim @@ -139,6 +139,7 @@ \ nosync \ noundef \ nounwind + \ nosanitize_bounds \ nosanitize_coverage \ null_pointer_is_valid \ optforfuzzing Index: llvm/utils/llvm.grm =================================================================== --- llvm/utils/llvm.grm +++ llvm/utils/llvm.grm @@ -176,6 +176,7 @@ | sanitize_thread | sanitize_memory | mustprogress + | nosanitize_bounds | nosanitize_coverage ; Index: llvm/utils/emacs/llvm-mode.el =================================================================== --- llvm/utils/emacs/llvm-mode.el +++ llvm/utils/emacs/llvm-mode.el @@ -25,7 +25,7 @@ '("alwaysinline" "argmemonly" "allocsize" "builtin" "cold" "convergent" "dereferenceable" "dereferenceable_or_null" "hot" "inaccessiblememonly" "inaccessiblemem_or_argmemonly" "inalloca" "inlinehint" "jumptable" "minsize" "mustprogress" "naked" "nobuiltin" "nonnull" "nocallback" "nocf_check" "noduplicate" "nofree" "noimplicitfloat" "noinline" "nomerge" "nonlazybind" "noprofile" "noredzone" "noreturn" - "norecurse" "nosync" "noundef" "nounwind" "nosanitize_coverage" "null_pointer_is_valid" "optforfuzzing" "optnone" "optsize" "preallocated" "readnone" "readonly" "returned" "returns_twice" + "norecurse" "nosync" "noundef" "nounwind" "nosanitize_bounds" "nosanitize_coverage" "null_pointer_is_valid" "optforfuzzing" "optnone" "optsize" "preallocated" "readnone" "readonly" "returned" "returns_twice" "shadowcallstack" "speculatable" "speculative_load_hardening" "ssp" "sspreq" "sspstrong" "safestack" "sanitize_address" "sanitize_hwaddress" "sanitize_memtag" "sanitize_thread" "sanitize_memory" "strictfp" "swifterror" "uwtable" "vscale_range" "willreturn" "writeonly" "immarg") 'symbols) . font-lock-constant-face) ;; Variables Index: llvm/test/Bitcode/compatibility.ll =================================================================== --- llvm/test/Bitcode/compatibility.ll +++ llvm/test/Bitcode/compatibility.ll @@ -1510,7 +1510,7 @@ ; CHECK: select <2 x i1> <i1 true, i1 false>, <2 x i8> <i8 2, i8 3>, <2 x i8> <i8 3, i8 2> call void @f.nobuiltin() builtin - ; CHECK: call void @f.nobuiltin() #48 + ; CHECK: call void @f.nobuiltin() #49 call fastcc noalias i32* @f.noalias() noinline ; CHECK: call fastcc noalias i32* @f.noalias() #12 @@ -1930,6 +1930,9 @@ ; CHECK: Function Attrs: allocsize(1,0) ; CHECK: declare void @f.allocsize_two(i32, i32) +declare void @f.nosanitize_bounds() nosanitize_bounds +; CHECK: declare void @f.nosanitize_bounds() #48 + ; CHECK: attributes #0 = { alignstack=4 } ; CHECK: attributes #1 = { alignstack=8 } ; CHECK: attributes #2 = { alwaysinline } @@ -1978,7 +1981,8 @@ ; CHECK: attributes #45 = { disable_sanitizer_instrumentation } ; CHECK: attributes #46 = { allocsize(0) } ; CHECK: attributes #47 = { allocsize(1,0) } -; CHECK: attributes #48 = { builtin } +; CHECK: attributes #48 = { nosanitize_bounds } +; CHECK: attributes #49 = { builtin } ;; Metadata Index: llvm/test/Bitcode/attributes.ll =================================================================== --- llvm/test/Bitcode/attributes.ll +++ llvm/test/Bitcode/attributes.ll @@ -526,6 +526,12 @@ ret void; } +; CHECK: define void @f86() #52 +define void @f86() nosanitize_bounds +{ + ret void; +} + ; CHECK: attributes #0 = { noreturn } ; CHECK: attributes #1 = { nounwind } ; CHECK: attributes #2 = { readnone } @@ -578,4 +584,5 @@ ; CHECK: attributes #49 = { noprofile } ; CHECK: attributes #50 = { disable_sanitizer_instrumentation } ; CHECK: attributes #51 = { uwtable(sync) } +; CHECK: attributes #52 = { nosanitize_bounds } ; CHECK: attributes #[[NOBUILTIN]] = { nobuiltin } Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp =================================================================== --- llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -939,6 +939,7 @@ case Attribute::NonLazyBind: case Attribute::NoRedZone: case Attribute::NoUnwind: + case Attribute::NoSanitizeBounds: case Attribute::NoSanitizeCoverage: case Attribute::NullPointerIsValid: case Attribute::OptForFuzzing: Index: llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp +++ llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp @@ -142,6 +142,9 @@ static bool addBoundsChecking(Function &F, TargetLibraryInfo &TLI, ScalarEvolution &SE) { + if (F.hasFnAttribute(Attribute::NoSanitizeBounds)) + return false; + const DataLayout &DL = F.getParent()->getDataLayout(); ObjectSizeOpts EvalOpts; EvalOpts.RoundToAlign = true; Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -688,6 +688,8 @@ return bitc::ATTR_KIND_NO_PROFILE; case Attribute::NoUnwind: return bitc::ATTR_KIND_NO_UNWIND; + case Attribute::NoSanitizeBounds: + return bitc::ATTR_KIND_NO_SANITIZE_BOUNDS; case Attribute::NoSanitizeCoverage: return bitc::ATTR_KIND_NO_SANITIZE_COVERAGE; case Attribute::NullPointerIsValid: Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp =================================================================== --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1493,6 +1493,8 @@ return Attribute::NoProfile; case bitc::ATTR_KIND_NO_UNWIND: return Attribute::NoUnwind; + case bitc::ATTR_KIND_NO_SANITIZE_BOUNDS: + return Attribute::NoSanitizeBounds; case bitc::ATTR_KIND_NO_SANITIZE_COVERAGE: return Attribute::NoSanitizeCoverage; case bitc::ATTR_KIND_NULL_POINTER_IS_VALID: Index: llvm/lib/AsmParser/LLLexer.cpp =================================================================== --- llvm/lib/AsmParser/LLLexer.cpp +++ llvm/lib/AsmParser/LLLexer.cpp @@ -672,6 +672,7 @@ KEYWORD(nocf_check); KEYWORD(noundef); KEYWORD(nounwind); + KEYWORD(nosanitize_bounds); KEYWORD(nosanitize_coverage); KEYWORD(null_pointer_is_valid); KEYWORD(optforfuzzing); Index: llvm/include/llvm/IR/Attributes.td =================================================================== --- llvm/include/llvm/IR/Attributes.td +++ llvm/include/llvm/IR/Attributes.td @@ -175,6 +175,9 @@ /// Function doesn't unwind stack. def NoUnwind : EnumAttr<"nounwind", [FnAttr]>; +/// No SanitizeBounds instrumentation. +def NoSanitizeBounds : EnumAttr<"nosanitize_bounds", [FnAttr]>; + /// No SanitizeCoverage instrumentation. def NoSanitizeCoverage : EnumAttr<"nosanitize_coverage", [FnAttr]>; Index: llvm/include/llvm/Bitcode/LLVMBitCodes.h =================================================================== --- llvm/include/llvm/Bitcode/LLVMBitCodes.h +++ llvm/include/llvm/Bitcode/LLVMBitCodes.h @@ -677,6 +677,7 @@ ATTR_KIND_NO_SANITIZE_COVERAGE = 76, ATTR_KIND_ELEMENTTYPE = 77, ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION = 78, + ATTR_KIND_NO_SANITIZE_BOUNDS = 79, }; enum ComdatSelectionKindCodes { Index: llvm/include/llvm/AsmParser/LLToken.h =================================================================== --- llvm/include/llvm/AsmParser/LLToken.h +++ llvm/include/llvm/AsmParser/LLToken.h @@ -219,6 +219,7 @@ kw_nosync, kw_nocf_check, kw_nounwind, + kw_nosanitize_bounds, kw_nosanitize_coverage, kw_null_pointer_is_valid, kw_optforfuzzing, Index: llvm/docs/LangRef.rst =================================================================== --- llvm/docs/LangRef.rst +++ llvm/docs/LangRef.rst @@ -1783,6 +1783,9 @@ trap or generate asynchronous exceptions. Exception handling schemes that are recognized by LLVM to handle asynchronous exceptions, such as SEH, will still provide their implementation defined semantics. +``nosanitize_bounds`` + This attribute indicates that bounds checking sanitizer instrumentation + is disabled for this function. ``nosanitize_coverage`` This attribute indicates that SanitizerCoverage instrumentation is disabled for this function. Index: llvm/docs/BitCodeFormat.rst =================================================================== --- llvm/docs/BitCodeFormat.rst +++ llvm/docs/BitCodeFormat.rst @@ -1078,6 +1078,7 @@ * code 76: ``nosanitize_coverage`` * code 77: ``elementtype`` * code 78: ``disable_sanitizer_instrumentation`` +* code 79: ``nosanitize_bounds`` .. note:: The ``allocsize`` attribute has a special encoding for its arguments. Its two Index: llvm/bindings/go/llvm/ir_test.go =================================================================== --- llvm/bindings/go/llvm/ir_test.go +++ llvm/bindings/go/llvm/ir_test.go @@ -69,6 +69,7 @@ "noredzone", "noreturn", "nounwind", + "nosanitize_bounds", "nosanitize_coverage", "optnone", "optsize", Index: clang/test/CodeGen/sanitize-coverage.c =================================================================== --- clang/test/CodeGen/sanitize-coverage.c +++ clang/test/CodeGen/sanitize-coverage.c @@ -53,6 +53,7 @@ // ASAN-NOT: call void @__asan_report_store // MSAN-NOT: call void @__msan_warning // BOUNDS-NOT: call void @__ubsan_handle_out_of_bounds + // BOUNDS-NOT: call void @llvm.trap() // TSAN-NOT: call void @__tsan_func_entry // UBSAN-NOT: call void @__ubsan_handle if (n) @@ -72,6 +73,7 @@ // ASAN-NOT: call void @__asan_report_store // MSAN-NOT: call void @__msan_warning // BOUNDS-NOT: call void @__ubsan_handle_out_of_bounds + // BOUNDS-NOT: call void @llvm.trap() // TSAN-NOT: call void @__tsan_func_entry // UBSAN-NOT: call void @__ubsan_handle if (n) Index: clang/lib/CodeGen/CodeGenFunction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenFunction.cpp +++ clang/lib/CodeGen/CodeGenFunction.cpp @@ -754,6 +754,10 @@ SanOpts.set(SanitizerKind::KernelHWAddress, false); if (mask & SanitizerKind::KernelHWAddress) SanOpts.set(SanitizerKind::HWAddress, false); + if (mask & SanitizerKind::LocalBounds) + Fn->addFnAttr(llvm::Attribute::NoSanitizeBounds); + if (mask & SanitizerKind::ArrayBounds) + Fn->addFnAttr(llvm::Attribute::NoSanitizeBounds); // SanitizeCoverage is not handled by SanOpts. if (Attr->hasCoverage())
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits