Index: include/clang/Basic/LangOptions.h =================================================================== --- include/clang/Basic/LangOptions.h +++ include/clang/Basic/LangOptions.h @@ -26,6 +26,7 @@ struct SanitizerOptions { #define SANITIZER(NAME, ID) unsigned ID : 1; #include "clang/Basic/Sanitizers.def" + unsigned AddressFieldPadding : 2; /// \brief Cached set of sanitizer options with all sanitizers disabled. static const SanitizerOptions Disabled; Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -526,6 +526,9 @@ def fno_sanitize_memory_track_origins : Flag<["-"], "fno-sanitize-memory-track-origins">, Group, Flags<[CC1Option]>, HelpText<"Disable origins tracking in MemorySanitizer">; +def fsanitize_address_field_padding : Joined<["-"], "fsanitize-address-field-padding=">, + Group, Flags<[CC1Option]>, + HelpText<"Level of field padding for AddressSanitizer">; def fsanitize_recover : Flag<["-"], "fsanitize-recover">, Group; def fno_sanitize_recover : Flag<["-"], "fno-sanitize-recover">, Index: include/clang/Driver/SanitizerArgs.h =================================================================== --- include/clang/Driver/SanitizerArgs.h +++ include/clang/Driver/SanitizerArgs.h @@ -49,6 +49,7 @@ std::string BlacklistFile; int MsanTrackOrigins; + int AsanFieldPadding; bool AsanZeroBaseShadow; bool UbsanTrapOnError; bool AsanSharedRuntime; Index: lib/Driver/SanitizerArgs.cpp =================================================================== --- lib/Driver/SanitizerArgs.cpp +++ lib/Driver/SanitizerArgs.cpp @@ -26,6 +26,7 @@ BlacklistFile = ""; MsanTrackOrigins = 0; AsanZeroBaseShadow = false; + AsanFieldPadding = 0; UbsanTrapOnError = false; AsanSharedRuntime = false; LinkCXXRuntimes = false; @@ -164,6 +165,15 @@ (TC.getTriple().getEnvironment() == llvm::Triple::Android); AsanZeroBaseShadow = (TC.getTriple().getEnvironment() == llvm::Triple::Android); + if (Arg *A = + Args.getLastArg(options::OPT_fsanitize_address_field_padding)) { + StringRef S = A->getValue(); + // Legal values are 0 and 1, but in future we may add more levels. + if (S.getAsInteger(0, AsanFieldPadding) || AsanFieldPadding < 0 || + AsanFieldPadding > 2) { + D.Diag(diag::err_drv_invalid_value) << A->getAsString(Args) << S; + } + } } // Parse -link-cxx-sanitizer flag. @@ -191,7 +201,9 @@ if (MsanTrackOrigins) CmdArgs.push_back(Args.MakeArgString("-fsanitize-memory-track-origins=" + llvm::utostr(MsanTrackOrigins))); - + if (AsanFieldPadding) + CmdArgs.push_back(Args.MakeArgString("-fsanitize-address-field-padding=" + + llvm::utostr(AsanFieldPadding))); // Workaround for PR16386. if (needsMsanRt()) CmdArgs.push_back(Args.MakeArgString("-fno-assume-sane-operator-new")); Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -1628,6 +1628,9 @@ break; } } + // -fsanitize-address-field-padding=N has to be a LangOpt, parse it here. + Opts.Sanitize.AddressFieldPadding = + getLastArgIntValue(Args, OPT_fsanitize_address_field_padding, 0, Diags); } static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,