Commit 6b2f0991 authored by Sylvain Henry's avatar Sylvain Henry Committed by Marge Bot

NCG: correctly escape path strings on Windows (#16389)

GHC native code generator generates .incbin and .file directives. We
need to escape those strings correctly on Windows (see #16389).
parent 6e3e537e
Pipeline #3301 passed with stages
in 468 minutes and 33 seconds
...@@ -461,7 +461,7 @@ cmmNativeGens dflags this_mod modLoc ncgImpl h dbgMap = go ...@@ -461,7 +461,7 @@ cmmNativeGens dflags this_mod modLoc ncgImpl h dbgMap = go
nonDetEltsUFM $ fileIds' `minusUFM` fileIds nonDetEltsUFM $ fileIds' `minusUFM` fileIds
-- See Note [Unique Determinism and code generation] -- See Note [Unique Determinism and code generation]
pprDecl (f,n) = text "\t.file " <> ppr n <+> pprDecl (f,n) = text "\t.file " <> ppr n <+>
doubleQuotes (ftext f) pprFilePathString (unpackFS f)
emitNativeCode dflags h $ vcat $ emitNativeCode dflags h $ vcat $
map pprDecl newFileIds ++ map pprDecl newFileIds ++
......
...@@ -143,7 +143,9 @@ pprBytes bs = sdocWithDynFlags $ \dflags -> ...@@ -143,7 +143,9 @@ pprBytes bs = sdocWithDynFlags $ \dflags ->
else unsafePerformIO $ do else unsafePerformIO $ do
bFile <- newTempName dflags TFL_CurrentModule ".dat" bFile <- newTempName dflags TFL_CurrentModule ".dat"
BS.writeFile bFile bs BS.writeFile bFile bs
return $ text "\t.incbin \"" <> text bFile <> text "\"\n\t.byte 0" return $ text "\t.incbin "
<> pprFilePathString bFile -- proper escape (see #16389)
<> text "\n\t.byte 0"
{- {-
Note [Embedding large binary blobs] Note [Embedding large binary blobs]
......
...@@ -56,7 +56,7 @@ module Outputable ( ...@@ -56,7 +56,7 @@ module Outputable (
pprPrimChar, pprPrimInt, pprPrimWord, pprPrimInt64, pprPrimWord64, pprPrimChar, pprPrimInt, pprPrimWord, pprPrimInt64, pprPrimWord64,
pprFastFilePath, pprFastFilePath, pprFilePathString,
-- * Controlling the style in which output is printed -- * Controlling the style in which output is printed
BindingSite(..), BindingSite(..),
...@@ -999,6 +999,16 @@ pprInfixVar is_operator pp_v ...@@ -999,6 +999,16 @@ pprInfixVar is_operator pp_v
pprFastFilePath :: FastString -> SDoc pprFastFilePath :: FastString -> SDoc
pprFastFilePath path = text $ normalise $ unpackFS path pprFastFilePath path = text $ normalise $ unpackFS path
-- | Normalise, escape and render a string representing a path
--
-- e.g. "c:\\whatever"
pprFilePathString :: FilePath -> SDoc
pprFilePathString path = doubleQuotes $ text (escape (normalise path))
where
escape [] = []
escape ('\\':xs) = '\\':'\\':escape xs
escape (x:xs) = x:escape xs
{- {-
************************************************************************ ************************************************************************
* * * *
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment