Skip to content

[Flang][Windows] Fix test_errors.py by enforcing UTF-8 encoding #134625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025

Conversation

omjavaid
Copy link
Contributor

@omjavaid omjavaid commented Apr 7, 2025

This patch fixes UnicodeDecodeError on Windows in test_errors.py. This issue was observed on the flang-arm64-windows-msvc buildbot. Semantics/OpenMP/interop-construct.f90 was crashing due to Python defaulting to the cp1252 codec on Windows.

I have fixed this by explicitly setting encoding="utf-8" when reading source files and invoking subprocess.run() in test_errors.py

flang-arm64-windows-msvc was running on stagging master which resulted in this issue not being fixed earlier.
https://lab.llvm.org/staging/#/builders/206

This patch fixes UnicodeDecodeError on Windows in test_errors.py.
This issue was observed on the flang-arm64-windows-msvc buildbot.
Semantics/OpenMP/interop-construct.f90 was crashing due to Python
defaulting to the cp1252 codec on Windows

I have fixed this by explicitly setting encoding="utf-8" when reading
source files and invoking subprocess.run() in test_errors.py

flang-arm64-windows-msvc was running on stagging master which resulted
in this issue not being fixed earlier.
https://lab.llvm.org/staging/#/builders/206
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Apr 7, 2025
@omjavaid omjavaid requested a review from luporl April 7, 2025 13:25
@llvmbot
Copy link
Member

llvmbot commented Apr 7, 2025

@llvm/pr-subscribers-flang-semantics

Author: Omair Javaid (omjavaid)

Changes

This patch fixes UnicodeDecodeError on Windows in test_errors.py. This issue was observed on the flang-arm64-windows-msvc buildbot. Semantics/OpenMP/interop-construct.f90 was crashing due to Python defaulting to the cp1252 codec on Windows.

I have fixed this by explicitly setting encoding="utf-8" when reading source files and invoking subprocess.run() in test_errors.py

flang-arm64-windows-msvc was running on stagging master which resulted in this issue not being fixed earlier.
https://lab.llvm.org/staging/#/builders/206


Full diff: https://github.com/llvm/llvm-project/pull/134625.diff

1 Files Affected:

  • (modified) flang/test/Semantics/test_errors.py (+2-1)
diff --git a/flang/test/Semantics/test_errors.py b/flang/test/Semantics/test_errors.py
index 63ff3367edefd..45684764a00e4 100755
--- a/flang/test/Semantics/test_errors.py
+++ b/flang/test/Semantics/test_errors.py
@@ -17,7 +17,7 @@
 
 cm.check_args(sys.argv)
 srcdir = cm.set_source(sys.argv[1])
-with open(srcdir, "r") as f:
+with open(srcdir, "r", encoding="utf-8") as f:
     src = f.readlines()
 actual = ""
 expect = ""
@@ -39,6 +39,7 @@
             check=True,
             universal_newlines=True,
             cwd=tmpdir,
+            encoding="utf-8",
         )
     except subprocess.CalledProcessError as e:
         log = e.stderr

@omjavaid omjavaid requested a review from ijan1 April 7, 2025 13:25
Copy link
Contributor

@luporl luporl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

The error message tested in Semantics/OpenMP/interop-construct.f90 uses a special char for fi, in the word specified, which is probably a typo and should be fixed too.

luporl added a commit to luporl/llvm-project that referenced this pull request Apr 7, 2025
Some error messages were using a special char for `fi`, in the
word `specified`, probably due to a typo.

This caused an error on Windows: llvm#134625
luporl added a commit that referenced this pull request Apr 7, 2025
Some error messages were using a special char for `fi`, in the
word `specified`, probably due to a typo.

This caused an error on Windows: #134625
@omjavaid omjavaid merged commit c2c1031 into llvm:main Apr 8, 2025
14 checks passed
@omjavaid omjavaid deleted the fix_flang_buildbot branch April 8, 2025 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants