diff --git a/cmd/deadcode/deadcode.go b/cmd/deadcode/deadcode.go
index e0fce428d08..6312c0097f3 100644
--- a/cmd/deadcode/deadcode.go
+++ b/cmd/deadcode/deadcode.go
@@ -348,6 +348,9 @@ func main() {
 		format = *formatFlag
 	}
 	printObjects(format, packages)
+	if len(packages) > 0 {
+		os.Exit(1)
+	}
 }
 
 // prettyName is a fork of Function.String designed to reduce
diff --git a/cmd/deadcode/deadcode_test.go b/cmd/deadcode/deadcode_test.go
index f17a1227362..205c8a1a169 100644
--- a/cmd/deadcode/deadcode_test.go
+++ b/cmd/deadcode/deadcode_test.go
@@ -113,17 +113,23 @@ func Test(t *testing.T) {
 					cmd.Env = append(os.Environ(), "GOPROXY=", "GO111MODULE=on")
 					var got string
 					if err := cmd.Run(); err != nil {
-						if !tc.wantErr {
-							t.Fatalf("deadcode failed: %v (stderr=%s)", err, cmd.Stderr)
+						switch err.(type) {
+						case *exec.ExitError:
+							if tc.wantErr {
+								got = fmt.Sprint(cmd.Stderr)
+							} else {
+								// If an unreachable code is detected, exit code 1 is notified
+								if cmd.ProcessState.ExitCode() != 1 {
+									t.Fatalf("deadcode failed: %v", err)
+								}
+								got = fmt.Sprint(cmd.Stdout)
+							}
+						default:
+							t.Fatalf("deadcode failed: %v", err)
 						}
-						got = fmt.Sprint(cmd.Stderr)
 					} else {
-						if tc.wantErr {
-							t.Fatalf("deadcode succeeded unexpectedly (stdout=%s)", cmd.Stdout)
-						}
 						got = fmt.Sprint(cmd.Stdout)
 					}
-
 					// Check each want directive.
 					for str, sense := range tc.want {
 						ok := true