Test Modules/macro-undef-through-pch.m causes internal error in llvm-lit

This test, and a few others, dump what is essentially binary data to stdout. This data trips up the cmake-detected Python interpreter (2.7.6) and causes the following error with a check-all build of LLVM:

Traceback (most recent call last):

File “/llvm-lit”, line 37, in

main(builtin_parameters)

File “llvm/utils/lit/lit/main.py”, line 193, in main

main_with_tmp(builtinParameters)

File “llvm/utils/lit/lit/main.py”, line 540, in main_with_tmp

write_test_results(run, litConfig, testing_time, opts.output_path)

File “llvm/utils/lit/lit/main.py”, line 153, in write_test_results

json.dump(data, f, indent=2, sort_keys=True)

File “/usr/lib/python2.7/json/init.py”, line 189, in dump

for chunk in iterable:

File “/usr/lib/python2.7/json/encoder.py”, line 434, in _iterencode

for chunk in _iterencode_dict(o, _current_indent_level):

File “/usr/lib/python2.7/json/encoder.py”, line 408, in _iterencode_dict

for chunk in chunks:

File “/usr/lib/python2.7/json/encoder.py”, line 332, in _iterencode_list

for chunk in chunks:

File “/usr/lib/python2.7/json/encoder.py”, line 390, in _iterencode_dict

yield _encoder(value)

UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0xce in position 2685: invalid continuation byte

ninja: build stopped: subcommand failed.

This test has existed in a similar format since it was committed 4 years ago.

I can reproduce this with the following directed llvm-lit invocation:

/path/to/llvm/bin/llvm-lit --output=a.json /path/to/clang/ --filter=macro-undef

Has anyone run into this issue before? It seems unlikely that no one has tried to dump the output of this test to a JSON file in 4 years, so I’m open to suggestions as to what I might be doing wrong.

Since the test does not attempt to use the result of the RUN, I have been able to ‘fix’ the issue with the following minor patch:

diff --git a/test/Modules/macro-undef-through-pch.m b/test/Modules/macro-undef-through-pch.m

index fc32229bec…c4ea3fb98a 100644

— a/test/Modules/macro-undef-through-pch.m

+++ b/test/Modules/macro-undef-through-pch.m

@@ -3,7 +3,7 @@

// RUN: -I%S/Inputs/macro-undef-through-pch -emit-pch \

// RUN: %S/Inputs/macro-undef-through-pch/foo.h -o %t.pch

// RUN: %clang_cc1 -x objective-c -fmodules -fimplicit-module-maps -fmodules-cache-path=%t \

-// RUN: -I%S/Inputs/macro-undef-through-pch -emit-pch \

+// RUN: -I%S/Inputs/macro-undef-through-pch -emit-pch -o %t.dummy.pch \

// RUN: -include-pch %t.pch %s

// PR19215

Regards,

J.B. Nagurne

Code Generation

Texas Instruments