commit e3dc9cf376c9ba41b1e9b98f221b3ab6462a502a
Author: Dmitry Goncharov <dgoncharov@users.sf.net>
Date:   Fri Dec 10 22:58:36 2021 -0500

    [SV 48643] Prereqs mentioned on unrelated rules are not intermediate.
    
    If a prerequisite of a pattern is explicitly mentioned as a prerequisite
    of an unrelated rule, it should not be considered an intermediate file.
    
    * src/implicit.c: Set is_explicit when a prerequisite is mentioned
    explicitly on an unrelated rule.
    * tests/scripts/features/double_colon: Add tests.
    * tests/scripts/features/grouped_targets: Ditto.
    * tests/scripts/features/implicit_search: Ditto.
    * tests/scripts/features/patternrules: Ditto.
    * tests/scripts/features/se_implicit: Ditto.
    * tests/scripts/features/statipattrules: Ditto.

diff --git a/tests/scripts/features/double_colon b/tests/scripts/features/double_colon
index b5b73f7..c4996e7 100644
--- a/tests/scripts/features/double_colon
+++ b/tests/scripts/features/double_colon
@@ -237,6 +237,20 @@ all: hello.z
 !,
               '', "#MAKE#: Nothing to be done for 'all'.\n");
 
+# subtest 3
+# hello.x is explicitly mentioned on an unrelated rule and thus is not an
+# intermediate file.
+# Terminal pattern rules do not apply anyway and there is no rule to built
+# 'hello.x'.
+touch('hello.z');
+run_make_test(q!
+all: hello.z
+%.z:: %.x; touch $@
+%.x: ;
+unrelated: hello.x
+!,
+              '', "#MAKE#: *** No rule to make target 'hello.x', needed by 'hello.z'.  Stop.\n", 512);
+
 unlink('hello.z');
 
 
diff --git a/tests/scripts/features/grouped_targets b/tests/scripts/features/grouped_targets
index 131b8c0..f6a1721 100644
--- a/tests/scripts/features/grouped_targets
+++ b/tests/scripts/features/grouped_targets
@@ -152,6 +152,16 @@ all: hello.z
 %.x: ;
 !, '', "hello.z hello.q\n");
 
+# subtest 3
+# hello.x is explicitly mentioned on an unrelated rule and thus is not an
+# intermediate file.
+run_make_test(q!
+all: hello.z
+%.z %.q: %.x; @echo $*.z $*.q
+%.x: ;
+unrelated: hello.x
+!, '', "hello.z hello.q\n");
+
 unlink('hello.z');
 unlink('hello.q');
 
diff --git a/tests/scripts/features/implicit_search b/tests/scripts/features/implicit_search
index 32c9a71..8bba11d 100644
--- a/tests/scripts/features/implicit_search
+++ b/tests/scripts/features/implicit_search
@@ -284,6 +284,18 @@ unrelated: hello$s
 }
 }
 
+# Test that prerequisite 'hello.x' mentioned explicitly on an unrelated rule is
+# not considered intermediate.
+touch('hello.tsk');
+unlink('hello.x');
+run_make_test("
+all: hello.tsk
+%.tsk: %.x; touch hello.tsk
+%.x: ;
+unrelated: hello.x
+", '', "touch hello.tsk\n");
+unlink('hello.tsk');
+
 touch ('hello.f');
 # Test implicit search of builtin rules.
 
diff --git a/tests/scripts/features/patternrules b/tests/scripts/features/patternrules
index 25a80e7..57a7fca 100644
--- a/tests/scripts/features/patternrules
+++ b/tests/scripts/features/patternrules
@@ -272,6 +272,18 @@ all: hello.z
 !,
               '', "touch hello.z");
 
+# subtest 3
+# hello.x is explicitly mentioned on an unrelated rule and thus is not an
+# intermediate file.
+touch('hello.z');
+run_make_test(q!
+all: hello.z
+%.z: %.x; touch $@
+%.x: ;
+unrelated: hello.x
+!,
+              '', "touch hello.z");
+
 unlink('hello.z');
 
 # sv 60188.
diff --git a/tests/scripts/features/se_implicit b/tests/scripts/features/se_implicit
index db6e168..712f3bf 100644
--- a/tests/scripts/features/se_implicit
+++ b/tests/scripts/features/se_implicit
@@ -291,6 +291,18 @@ all: hello.z
 %.x: ;
 !, '', "hello.z\n");
 
+# subtest 3.
+# hello.x is explicitly mentioned on an unrelated rule and thus is not an
+# intermediate file.
+run_make_test(q!
+.SECONDEXPANSION:
+dep:=hello.x
+all: hello.z
+%.z: %.x; @echo $@
+%.x: ;
+unrelated: $$(dep)
+!, '', "hello.z\n");
+
 unlink('hello.z');
 
 
diff --git a/tests/scripts/features/statipattrules b/tests/scripts/features/statipattrules
index 096521e..378fedc 100644
--- a/tests/scripts/features/statipattrules
+++ b/tests/scripts/features/statipattrules
@@ -123,10 +123,19 @@ hello.z: %.z: %.x ; @echo $@
 
 # subtest 2
 run_make_test(q!
-hello.z: %.z: test.x ; @echo $@
+hello.z: %.z: %.x test.x ; @echo $@
 %.x: ;
 !, '', "hello.z\n");
 
+# subtest 3
+# 'hello.x' is mentioned explicitly on an unrelated rule.
+run_make_test(q!
+hello.z: %.z: %.x ; @echo $@
+%.x: ;
+unrelated: hello.x
+!, '', "hello.z\n");
+
+
 unlink('hello.z');
 
 1;
