diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -222,6 +222,10 @@ ENUM_CODEGENOPT(SanitizeAddressDtorKind, llvm::AsanDtorKind, 2, llvm::AsanDtorKind::Global) ///< Set how ASan global ///< destructors are emitted. +ENUM_CODEGENOPT(SanitizeAddressDetectStackUseAfterReturn, + llvm::AsanDetectStackUseAfterReturnKind, 2, + llvm::AsanDetectStackUseAfterReturnKind::Runtime + ) ///< Set detection mode for stack-use-after-return. CODEGENOPT(SanitizeMemoryUseAfterDtor, 1, 0) ///< Enable use-after-delete detection ///< in MemorySanitizer CODEGENOPT(SanitizeCfiCrossDso, 1, 0) ///< Enable cross-dso support in CFI. diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1544,6 +1544,16 @@ NormalizedValuesScope<"llvm::AsanDtorKind">, NormalizedValues<["None", "Global"]>, MarshallingInfoEnum, "Global">; +def sanitize_address_detect_stack_use_after_return_EQ + : Joined<["-"], "fsanitize-address-detect-stack-use-after-return=">, + MetaVarName<"">, + Flags<[CC1Option]>, + HelpText<"Select the enabling method of detect-stack-use-after-return in AddressSanitizer">, + Group, + Values<"never,runtime,always">, + NormalizedValuesScope<"llvm::AsanDetectStackUseAfterReturnKind">, + NormalizedValues<["Never", "Runtime", "Always"]>, + MarshallingInfoEnum, "Runtime">; // Note: This flag was introduced when it was necessary to distinguish between // ABI for correct codegen. This is no longer needed, but the flag is // not removed since targeting either ABI will behave the same. diff --git a/llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h b/llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h --- a/llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h +++ b/llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h @@ -20,5 +20,16 @@ Invalid, ///< Not a valid destructor Kind. // TODO(dliew): Add more more kinds. }; + +/// Kinds of ASan detect stack use after return +enum class AsanDetectStackUseAfterReturnKind { + Never, ///< Never detect stack use after return. + Runtime, ///< Detect stack use after return if runtime flag is enabled + ///< (ASAN_OPTIONS=detect_stack_use_after_return=1) + Always, ///< Always detect stack use after return. + Invalid, ///< Not a valid detect mode. +}; + } // namespace llvm + #endif