<br><br><div class="gmail_quote">On Wed, Nov 16, 2011 at 6:10 PM, Chris Lattner <span dir="ltr"><<a href="mailto:clattner@apple.com">clattner@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
On Nov 16, 2011, at 9:34 AM, Kostya Serebryany wrote:<br>
<br>
> Author: kcc<br>
> Date: Wed Nov 16 11:34:26 2011<br>
> New Revision: 144800<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=144800&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=144800&view=rev</a><br>
> Log:<br>
> Add -f[no-]address-sanitizer flag<br>
<br>
</div>Great! Please document this in the user's manual,<br></blockquote><div><br></div><div>Probably, not before it actually becomes usable. </div><div>(We still need the run-time library and then the linker flags; working on that)</div>
<div>--kcc </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
-Chris<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
> Modified:<br>
> cfe/trunk/include/clang/Driver/CC1Options.td<br>
> cfe/trunk/include/clang/Driver/Options.td<br>
> cfe/trunk/include/clang/Frontend/CodeGenOptions.h<br>
> cfe/trunk/lib/CodeGen/BackendUtil.cpp<br>
> cfe/trunk/lib/Driver/Tools.cpp<br>
> cfe/trunk/lib/Frontend/CompilerInvocation.cpp<br>
><br>
> Modified: cfe/trunk/include/clang/Driver/CC1Options.td<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=144800&r1=144799&r2=144800&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=144800&r1=144799&r2=144800&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/Driver/CC1Options.td (original)<br>
> +++ cfe/trunk/include/clang/Driver/CC1Options.td Wed Nov 16 11:34:26 2011<br>
> @@ -114,6 +114,8 @@<br>
> HelpText<"The compilation directory to embed in the debug info.">;<br>
> def dwarf_debug_flags : Separate<"-dwarf-debug-flags">,<br>
> HelpText<"The string to embed in the Dwarf debug flags record.">;<br>
> +def faddress_sanitizer: Flag<"-faddress-sanitizer">,<br>
> + HelpText<"Enable AddressSanitizer instrumentation (memory error detection)">;<br>
> def fforbid_guard_variables : Flag<"-fforbid-guard-variables">,<br>
> HelpText<"Emit an error if a C++ static local initializer would need a guard variable">;<br>
> def g : Flag<"-g">, HelpText<"Generate source level debug information">;<br>
><br>
> Modified: cfe/trunk/include/clang/Driver/Options.td<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=144800&r1=144799&r2=144800&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=144800&r1=144799&r2=144800&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/Driver/Options.td (original)<br>
> +++ cfe/trunk/include/clang/Driver/Options.td Wed Nov 16 11:34:26 2011<br>
> @@ -262,6 +262,8 @@<br>
> def fallow_unsupported : Flag<"-fallow-unsupported">, Group<f_Group>;<br>
> def fapple_kext : Flag<"-fapple-kext">, Group<f_Group>;<br>
> def fapple_pragma_pack : Flag<"-fapple-pragma-pack">, Group<f_Group>;<br>
> +def faddress_sanitizer : Flag<"-faddress-sanitizer">, Group<f_Group>;<br>
> +def fno_address_sanitizer : Flag<"-fno-address-sanitizer">, Group<f_Group>;<br>
> def fasm : Flag<"-fasm">, Group<f_Group>;<br>
><br>
> def fasm_blocks : Flag<"-fasm-blocks">, Group<f_Group>;<br>
><br>
> Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.h?rev=144800&r1=144799&r2=144800&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.h?rev=144800&r1=144799&r2=144800&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/Frontend/CodeGenOptions.h (original)<br>
> +++ cfe/trunk/include/clang/Frontend/CodeGenOptions.h Wed Nov 16 11:34:26 2011<br>
> @@ -35,6 +35,7 @@<br>
> Mixed = 2<br>
> };<br>
><br>
> + unsigned AddressSanitizer : 1; /// Enable AddressSanitizer.<br>
> unsigned AsmVerbose : 1; /// -dA, -fverbose-asm.<br>
> unsigned ObjCAutoRefCountExceptions : 1; /// Whether ARC should be EH-safe.<br>
> unsigned CUDAIsDevice : 1; /// Set when compiling for CUDA device.<br>
> @@ -151,6 +152,7 @@<br>
><br>
> public:<br>
> CodeGenOptions() {<br>
> + AddressSanitizer = 0;<br>
> AsmVerbose = 0;<br>
> CUDAIsDevice = 0;<br>
> CXAAtExit = 1;<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=144800&r1=144799&r2=144800&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=144800&r1=144799&r2=144800&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Wed Nov 16 11:34:26 2011<br>
> @@ -115,6 +115,11 @@<br>
> PM.add(createObjCARCOptPass());<br>
> }<br>
><br>
> +static void addAddressSanitizerPass(const PassManagerBuilder &Builder,<br>
> + PassManagerBase &PM) {<br>
> + PM.add(createAddressSanitizerPass());<br>
> +}<br>
> +<br>
> void EmitAssemblyHelper::CreatePasses() {<br>
> unsigned OptLevel = CodeGenOpts.OptimizationLevel;<br>
> CodeGenOptions::InliningMethod Inlining = CodeGenOpts.Inlining;<br>
> @@ -141,6 +146,11 @@<br>
> PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate,<br>
> addObjCARCOptPass);<br>
> }<br>
> +<br>
> + if (CodeGenOpts.AddressSanitizer) {<br>
> + PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate,<br>
> + addAddressSanitizerPass);<br>
> + }<br>
><br>
> // Figure out TargetLibraryInfo.<br>
> Triple TargetTriple(TheModule->getTargetTriple());<br>
><br>
> Modified: cfe/trunk/lib/Driver/Tools.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=144800&r1=144799&r2=144800&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=144800&r1=144799&r2=144800&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Driver/Tools.cpp (original)<br>
> +++ cfe/trunk/lib/Driver/Tools.cpp Wed Nov 16 11:34:26 2011<br>
> @@ -1701,6 +1701,10 @@<br>
> if (getToolChain().SupportsProfiling())<br>
> Args.AddLastArg(CmdArgs, options::OPT_pg);<br>
><br>
> + if (Args.hasFlag(options::OPT_faddress_sanitizer,<br>
> + options::OPT_fno_address_sanitizer, false))<br>
> + CmdArgs.push_back("-faddress-sanitizer");<br>
> +<br>
> // -flax-vector-conversions is default.<br>
> if (!Args.hasFlag(options::OPT_flax_vector_conversions,<br>
> options::OPT_fno_lax_vector_conversions))<br>
><br>
> Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=144800&r1=144799&r2=144800&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=144800&r1=144799&r2=144800&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)<br>
> +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed Nov 16 11:34:26 2011<br>
> @@ -139,6 +139,8 @@<br>
> Res.push_back("-dwarf-debug-flags");<br>
> Res.push_back(Opts.DwarfDebugFlags);<br>
> }<br>
> + if (Opts.AddressSanitizer)<br>
> + Res.push_back("-faddress-sanitizer");<br>
> if (Opts.ObjCRuntimeHasARC)<br>
> Res.push_back("-fobjc-runtime-has-arc");<br>
> if (Opts.ObjCRuntimeHasTerminate)<br>
> @@ -1049,6 +1051,7 @@<br>
> Opts.UnrollLoops = Args.hasArg(OPT_funroll_loops) ||<br>
> (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize);<br>
><br>
> + Opts.AddressSanitizer = Args.hasArg(OPT_faddress_sanitizer);<br>
> Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose);<br>
> Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions);<br>
> Opts.ObjCRuntimeHasARC = Args.hasArg(OPT_fobjc_runtime_has_arc);<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br>
</div></div></blockquote></div><br>