Skip to content

[MinGW] tooling crash on duplicate environment variable names #84428

@RivenSkaye

Description

@RivenSkaye

Description

On Windows, in shells and environments that allow to differentiate casing on env vars, the swift tooling (swift.exe) crashes on duplicate variable names (e.g. tmp=... and TMP=...).

This is a problem in the case for environments like Git for Windows's Bash shell, MSYS2 environments, etc. where it's nice to just have all tools in one shell instance, for example in order to test code before pushing it.

Reproduction

> TMP="/tmp" tmp="$TMP" swift --version
Swift/NativeDictionary.swift:783: Fatal error: Duplicate values for key: 'ProcessEnvironmentKey(value: "tmp")'
Illegal instruction

# Expected output on a fresh install:
# Swift version 6.1.2 (swift-6.1.2-RELEASE)
# Target: x86_64-unknown-windows-msvc

Stack dump

Swift/NativeDictionary.swift:783: Fatal error: Duplicate values for key: 'ProcessEnvironmentKey(value: "tmp")'
Illegal instruction

Expected behavior

Printing the version information for the compiler and/or other tooling installed

Environment

Swift version 6.1.2 (swift-6.1.2-RELEASE)
MSYSTEM=MINGW64
MSYSTEM_CARCH=x86_64
MSYSTEM_CHOST=x86_64-w64-mingw32
MSYSTEM_PREFIX=/mingw64
tmp=C:\Users\Riven\AppData\Local\Temp
TEMP=/tmp
ORIGINAL_TMP=/c/Users/Martin/AppData/Local/Temp
TMP=/tmp

Additional information

This problem does not exist in a simple cmd.exe session or in PowerShell, where variable name casing is ignored and instead the last definition of the same name is used.

Potential fixes here would be to

  • only use the last definition
  • only use the first definition
  • don't disallow different casing (although this might break existing code if it depends on case insensitivity)

Metadata

Metadata

Assignees

No one assigned

    Labels

    WindowsPlatform: Windowstriage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions