diff --git a/gcc/testsuite/gcc.dg/pr69181-1.c b/gcc/testsuite/gcc.dg/pr69181-1.c
new file mode 100644
index 0000000..e851f0c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr69181-1.c
@@ -0,0 +1,7 @@
+/* { dg-do compile { target this_will_not_be_matched-*-* } } */
+
+/* { dg-begin-multiline-output "" }
+   This message should never be checked for.
+   In particular, it shouldn't be checked for in the *next*
+   test case.
+   { dg-end-multiline-output "" } */
diff --git a/gcc/testsuite/gcc.dg/pr69181-2.c b/gcc/testsuite/gcc.dg/pr69181-2.c
new file mode 100644
index 0000000..dca90dc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr69181-2.c
@@ -0,0 +1,4 @@
+/* Dummy test case, to verify that the dg-begin-multiline-output directive
+   from pr69181-1.c isn't erroneously expected to be handled in *this*
+   test case.  */
+int make_non_empty;
diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
index f9ec206..c003328 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -826,33 +826,21 @@ proc output-exists-not { args } {
 if { [info procs saved-dg-test] == [list] } {
     rename dg-test saved-dg-test
 
-    proc dg-test { args } {
+    # Helper function for cleanups that should happen after the call
+    # to the real dg-test, whether or not it returns normally, or
+    # fails with an error.
+    proc cleanup-after-saved-dg-test { } {
 	global additional_files
 	global additional_sources
+	global additional_sources_used
 	global additional_prunes
-	global errorInfo
 	global compiler_conditional_xfail_data
 	global shouldfail
 	global testname_with_flags
 	global set_target_env_var
 	global keep_saved_temps_suffixes
+	global multiline_expected_outputs
 
-	if { [ catch { eval saved-dg-test $args } errmsg ] } {
-	    set saved_info $errorInfo
-	    set additional_files ""
-	    set additional_sources ""
-	    set additional_sources_used ""
-	    set additional_prunes ""
-	    set shouldfail 0
-	    if [info exists compiler_conditional_xfail_data] {
-		unset compiler_conditional_xfail_data
-	    }
-	    if [info exists testname_with_flags] {
-		unset testname_with_flags
-	    }
-	    unset_timeout_vars
-	    error $errmsg $saved_info
-	}
 	set additional_files ""
 	set additional_sources ""
 	set additional_sources_used ""
@@ -871,6 +859,18 @@ if { [info procs saved-dg-test] == [list] } {
 	if [info exists testname_with_flags] {
 	    unset testname_with_flags
 	}
+	set multiline_expected_outputs []
+    }
+
+    proc dg-test { args } {
+	global errorInfo
+
+	if { [ catch { eval saved-dg-test $args } errmsg ] } {
+	    set saved_info $errorInfo
+	    cleanup-after-saved-dg-test
+	    error $errmsg $saved_info
+	}
+	cleanup-after-saved-dg-test
     }
 }
 
diff --git a/gcc/testsuite/lib/multiline.exp b/gcc/testsuite/lib/multiline.exp
index 6b2c1da..fd7affc 100644
--- a/gcc/testsuite/lib/multiline.exp
+++ b/gcc/testsuite/lib/multiline.exp
@@ -47,17 +47,18 @@
 # to have the testsuite verify the expected output.
 
 ############################################################################
-# Global variables.  Although global, these are intended to only be used from
-# within multiline.exp.
+# Global variables.
 ############################################################################
 
+# This is intended to only be used from within multiline.exp.
 # The line number of the last dg-begin-multiline-output directive.
 set _multiline_last_beginning_line -1
 
 # A list of
 #   first-line-number, last-line-number, lines
 # where each "lines" is a list of strings.
-set _multiline_expected_outputs []
+# This is cleared at the end of each test by gcc-dg.exp's wrapper for dg-test.
+set multiline_expected_outputs []
 
 ############################################################################
 # Exported functions.
@@ -94,9 +95,9 @@ proc dg-end-multiline-output { args } {
     verbose "lines: $lines" 3
     # Create an entry of the form:  first-line, last-line, lines
     set entry [list $_multiline_last_beginning_line $line $lines]
-    global _multiline_expected_outputs
-    lappend _multiline_expected_outputs $entry
-    verbose "within dg-end-multiline-output: _multiline_expected_outputs: $_multiline_expected_outputs" 3
+    global multiline_expected_outputs
+    lappend multiline_expected_outputs $entry
+    verbose "within dg-end-multiline-output: multiline_expected_outputs: $multiline_expected_outputs" 3
 
     set _multiline_last_beginning_line -1
 }
@@ -107,14 +108,12 @@ proc dg-end-multiline-output { args } {
 # those that weren't found.
 #
 # It returns a pruned version of its output.
-#
-# It also clears the list of expected multiline outputs.
 
 proc handle-multiline-outputs { text } {
-    global _multiline_expected_outputs
+    global multiline_expected_outputs
     global testname_with_flags
     set index 0
-    foreach entry $_multiline_expected_outputs {
+    foreach entry $multiline_expected_outputs {
 	verbose "  entry: $entry" 3
 	set start_line [lindex $entry 0]
 	set end_line   [lindex $entry 1]
@@ -140,9 +139,6 @@ proc handle-multiline-outputs { text } {
 	set index [expr $index + 1]
     }
 
-    # Clear the list of expected multiline outputs
-    set _multiline_expected_outputs []
-
     return $text
 }
 
