--- gcc/testsuite/lib/asan-dg.exp.jj	2012-11-14 09:11:13.086054131 +0100
+++ gcc/testsuite/lib/asan-dg.exp	2012-11-14 10:37:18.904032326 +0100
@@ -0,0 +1,88 @@
+# Copyright (C) 2012 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+load_lib target-libpath.exp
+
+# Return 1 if compilation with -faddress-sanitizer is error-free for trivial
+# code, 0 otherwise.
+
+proc check_effective_target_faddress_sanitizer {} {
+    return [check_no_compiler_messages faddress_sanitizer object {
+        void foo (void) { }
+    } "-faddress-sanitizer"]
+}
+
+#
+# asan_link_flags -- compute library path and flags to find libasan.
+# (originally from g++.exp)
+#
+
+proc asan_link_flags { paths } {
+    global srcdir
+    global ld_library_path
+    global shlib_ext
+
+    set gccpath ${paths}
+    set flags ""
+
+    set shlib_ext [get_shlib_extension]
+
+    if { $gccpath != "" } {
+      if { [file exists "${gccpath}/libsanitizer/asan/.libs/libasan.a"]
+	   || [file exists "${gccpath}/libsanitizer/asan/.libs/libasan.${shlib_ext}"] } {
+          append flags " -L${gccpath}/libsanitizer/asan/.libs "
+          append ld_library_path ":${gccpath}/libsanitizer/asan/.libs"
+      }
+    } else {
+      global tool_root_dir
+
+      set libasan [lookfor_file ${tool_root_dir} libasan]
+      if { $libasan != "" } {
+          append flags "-L${libasan} "
+          append ld_library_path ":${libasan}"
+      }
+    }
+
+    set_ld_library_path_env_vars
+
+    return "$flags"
+}
+
+#
+# asan_init -- called at the start of each subdir of tests
+#
+
+proc asan_init { args } {
+    global TEST_ALWAYS_FLAGS
+    global ALWAYS_CXXFLAGS
+    global TOOL_OPTIONS
+
+    set link_flags ""
+    if ![is_remote host] {
+	if [info exists TOOL_OPTIONS] {
+	    set link_flags "[asan_link_flags [get_multilibs ${TOOL_OPTIONS}]]"
+	} else {
+	    set link_flags "[asan_link_flags [get_multilibs]]"
+	}
+    }
+
+    if [info exists ALWAYS_CXXFLAGS] {
+	set ALWAYS_CXXFLAGS [concat "{ldflags=$link_flags}" $ALWAYS_CXXFLAGS]
+	set ALWAYS_CXXFLAGS [concat "{additional_flags=-faddress-sanitizer}" $ALWAYS_CXXFLAGS]
+    } else {
+	set TEST_ALWAYS_FLAGS "$link_flags -faddress-sanitizer $TEST_ALWAYS_FLAGS"
+    }
+}
--- gcc/testsuite/gcc.dg/asan/asan.exp.jj	2012-11-14 10:25:31.504713624 +0100
+++ gcc/testsuite/gcc.dg/asan/asan.exp	2012-11-14 10:27:08.109935623 +0100
@@ -0,0 +1,37 @@
+# Copyright (C) 2012 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Load support procs.
+load_lib gcc-dg.exp
+load_lib asan-dg.exp
+
+if ![check_effective_target_faddress_sanitizer] {
+  return
+}
+
+# Initialize `dg'.
+dg-init
+asan_init
+
+# Main loop.
+gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.c $srcdir/c-c++-common/asan/*.c]] ""
+
+# All done.
+dg-finish
--- gcc/testsuite/g++.dg/dg.exp.jj	2011-11-10 18:09:12.000000000 +0100
+++ gcc/testsuite/g++.dg/dg.exp	2012-11-14 09:07:04.043033232 +0100
@@ -1,4 +1,5 @@
-#   Copyright (C) 2000, 2007, 2009, 2010 Free Software Foundation, Inc.
+#   Copyright (C) 2000, 2007, 2009, 2010, 2011, 2012
+#   Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -50,6 +51,7 @@ set tests [prune $tests $srcdir/$subdir/
 set tests [prune $tests $srcdir/$subdir/tm/*]
 set tests [prune $tests $srcdir/$subdir/guality/*]
 set tests [prune $tests $srcdir/$subdir/simulate-thread/*]
+set tests [prune $tests $srcdir/$subdir/asan/*]
 
 # Main loop.
 g++-dg-runtest $tests $DEFAULT_CXXFLAGS
--- gcc/testsuite/g++.dg/asan/asan.exp.jj	2012-11-14 09:08:58.748511740 +0100
+++ gcc/testsuite/g++.dg/asan/asan.exp	2012-11-14 10:27:13.571985934 +0100
@@ -0,0 +1,35 @@
+# Copyright (C) 2012 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# Load support procs.
+load_lib g++-dg.exp
+load_lib asan-dg.exp
+
+if ![check_effective_target_faddress_sanitizer] {
+  return
+}
+
+# Initialize `dg'.
+dg-init
+asan_init
+
+# Main loop.
+gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.C $srcdir/c-c++-common/asan/*.c]] ""
+
+# All done.
+dg-finish
--- gcc/testsuite/c-c++-common/asan/memcmp-1.c.jj	2012-11-14 10:21:19.881128491 +0100
+++ gcc/testsuite/c-c++-common/asan/memcmp-1.c	2012-11-14 10:21:15.820152280 +0100
@@ -0,0 +1,16 @@
+/* { dg-do run } */
+/* { dg-options "-fno-builtin-memcmp" } */
+/* { dg-shouldfail "asan" } */
+
+#include <string.h>
+
+int
+main (int argc, char **argv)
+{
+  char a1[] = {argc, 2, 3, 4};
+  char a2[] = {1, 2*argc, 3, 4};
+  int res = memcmp (a1, a2, 5 + argc);
+  return res;
+}
+
+/* { dg-output "ERROR: AddressSanitizer stack-buffer-overflow.*" } */
