Add -f[no-]address-sanitizer flag

llvm-svn: 144800
This commit is contained in:
Kostya Serebryany 2011-11-16 17:34:26 +00:00
parent 10f4d06b81
commit 8855ff61cb
6 changed files with 23 additions and 0 deletions

View File

@ -114,6 +114,8 @@ def fdebug_compilation_dir : Separate<"-fdebug-compilation-dir">,
HelpText<"The compilation directory to embed in the debug info.">;
def dwarf_debug_flags : Separate<"-dwarf-debug-flags">,
HelpText<"The string to embed in the Dwarf debug flags record.">;
def faddress_sanitizer: Flag<"-faddress-sanitizer">,
HelpText<"Enable AddressSanitizer instrumentation (memory error detection)">;
def fforbid_guard_variables : Flag<"-fforbid-guard-variables">,
HelpText<"Emit an error if a C++ static local initializer would need a guard variable">;
def g : Flag<"-g">, HelpText<"Generate source level debug information">;

View File

@ -262,6 +262,8 @@ def faccess_control : Flag<"-faccess-control">, Group<f_Group>;
def fallow_unsupported : Flag<"-fallow-unsupported">, Group<f_Group>;
def fapple_kext : Flag<"-fapple-kext">, Group<f_Group>;
def fapple_pragma_pack : Flag<"-fapple-pragma-pack">, Group<f_Group>;
def faddress_sanitizer : Flag<"-faddress-sanitizer">, Group<f_Group>;
def fno_address_sanitizer : Flag<"-fno-address-sanitizer">, Group<f_Group>;
def fasm : Flag<"-fasm">, Group<f_Group>;
def fasm_blocks : Flag<"-fasm-blocks">, Group<f_Group>;

View File

@ -35,6 +35,7 @@ public:
Mixed = 2
};
unsigned AddressSanitizer : 1; /// Enable AddressSanitizer.
unsigned AsmVerbose : 1; /// -dA, -fverbose-asm.
unsigned ObjCAutoRefCountExceptions : 1; /// Whether ARC should be EH-safe.
unsigned CUDAIsDevice : 1; /// Set when compiling for CUDA device.
@ -151,6 +152,7 @@ public:
public:
CodeGenOptions() {
AddressSanitizer = 0;
AsmVerbose = 0;
CUDAIsDevice = 0;
CXAAtExit = 1;

View File

@ -115,6 +115,11 @@ static void addObjCARCOptPass(const PassManagerBuilder &Builder, PassManagerBase
PM.add(createObjCARCOptPass());
}
static void addAddressSanitizerPass(const PassManagerBuilder &Builder,
PassManagerBase &PM) {
PM.add(createAddressSanitizerPass());
}
void EmitAssemblyHelper::CreatePasses() {
unsigned OptLevel = CodeGenOpts.OptimizationLevel;
CodeGenOptions::InliningMethod Inlining = CodeGenOpts.Inlining;
@ -141,6 +146,11 @@ void EmitAssemblyHelper::CreatePasses() {
PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate,
addObjCARCOptPass);
}
if (CodeGenOpts.AddressSanitizer) {
PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate,
addAddressSanitizerPass);
}
// Figure out TargetLibraryInfo.
Triple TargetTriple(TheModule->getTargetTriple());

View File

@ -1701,6 +1701,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (getToolChain().SupportsProfiling())
Args.AddLastArg(CmdArgs, options::OPT_pg);
if (Args.hasFlag(options::OPT_faddress_sanitizer,
options::OPT_fno_address_sanitizer, false))
CmdArgs.push_back("-faddress-sanitizer");
// -flax-vector-conversions is default.
if (!Args.hasFlag(options::OPT_flax_vector_conversions,
options::OPT_fno_lax_vector_conversions))

View File

@ -139,6 +139,8 @@ static void CodeGenOptsToArgs(const CodeGenOptions &Opts,
Res.push_back("-dwarf-debug-flags");
Res.push_back(Opts.DwarfDebugFlags);
}
if (Opts.AddressSanitizer)
Res.push_back("-faddress-sanitizer");
if (Opts.ObjCRuntimeHasARC)
Res.push_back("-fobjc-runtime-has-arc");
if (Opts.ObjCRuntimeHasTerminate)
@ -1049,6 +1051,7 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
Opts.UnrollLoops = Args.hasArg(OPT_funroll_loops) ||
(Opts.OptimizationLevel > 1 && !Opts.OptimizeSize);
Opts.AddressSanitizer = Args.hasArg(OPT_faddress_sanitizer);
Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose);
Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions);
Opts.ObjCRuntimeHasARC = Args.hasArg(OPT_fobjc_runtime_has_arc);