diff options
author | Ben Gamari <ben@smart-cactus.org> | 2021-11-29 16:12:59 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2021-12-03 12:55:34 -0500 |
commit | a4683970c103f0707d09ed2d0d0fca7408baed03 (patch) | |
tree | ac9dc7b5b08cee6c6cd9fd6295d7b2f4928d1f79 | |
parent | 14e9cab675f5b0abf2c303a0aa455237768103d1 (diff) | |
download | haskell-a4683970c103f0707d09ed2d0d0fca7408baed03.tar.gz |
compiler: Eliminate accidental loop in GHC.SysTools.BaseDirwip/T20757
As noted in #20757, `GHC.SysTools.BaseDir.findToolDir` previously
contained an loop, which would be triggered in the case that the search
failed.
Closes #20757.
-rw-r--r-- | compiler/GHC/SysTools/BaseDir.hs | 4 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/T20757.hs | 6 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/T20757.stderr | 1 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/all.T | 7 |
4 files changed, 14 insertions, 4 deletions
diff --git a/compiler/GHC/SysTools/BaseDir.hs b/compiler/GHC/SysTools/BaseDir.hs index c0a1fa2cee..5d86ee6925 100644 --- a/compiler/GHC/SysTools/BaseDir.hs +++ b/compiler/GHC/SysTools/BaseDir.hs @@ -196,11 +196,11 @@ findToolDir False top_dir = go 0 (top_dir </> "..") [] InstallationError $ "could not detect mingw toolchain in the following paths: " ++ show tried | otherwise = do let try = path </> "mingw" - let tried = tried ++ [try] + let tried' = tried ++ [try] oneLevel <- doesDirectoryExist try if oneLevel then return (Just path) - else go (k+1) (path </> "..") tried + else go (k+1) (path </> "..") tried' findToolDir True _ = return Nothing #else findToolDir _ _ = return Nothing diff --git a/testsuite/tests/ghc-api/T20757.hs b/testsuite/tests/ghc-api/T20757.hs new file mode 100644 index 0000000000..b6af7815e8 --- /dev/null +++ b/testsuite/tests/ghc-api/T20757.hs @@ -0,0 +1,6 @@ +module Main where + +import GHC.SysTools.BaseDir + +main :: IO () +main = findToolDir False "/" >>= print diff --git a/testsuite/tests/ghc-api/T20757.stderr b/testsuite/tests/ghc-api/T20757.stderr new file mode 100644 index 0000000000..34678db7e3 --- /dev/null +++ b/testsuite/tests/ghc-api/T20757.stderr @@ -0,0 +1 @@ +T20757: could not detect mingw toolchain in the following paths: ["/..//mingw","/..//..//mingw","/..//..//..//mingw"] diff --git a/testsuite/tests/ghc-api/all.T b/testsuite/tests/ghc-api/all.T index 8eecd3c799..4d62a57682 100644 --- a/testsuite/tests/ghc-api/all.T +++ b/testsuite/tests/ghc-api/all.T @@ -30,5 +30,8 @@ test('T18522-dbg-ppr', compile_and_run, ['-package ghc']) test('T19156', extra_run_opts('"' + config.libdir + '"'), - compile_and_run, - ['-package ghc']) + compile_and_run, + ['-package ghc']) +test('T20757', [unless(opsys('mingw32'), skip), exit_code(1)], + compile_and_run, + ['-package ghc']) |