This is an archive of the discontinued LLVM Phabricator instance.

[libc++][NFC] Mark values in gdb pretty print comparison functions as live to prevent values being optimized out.
ClosedPublic

Authored by amyk on Sep 2 2021, 4:03 PM.

Details

Summary

It appears when testing LLVM 13 on Power, we run into failures with the libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
test case optimizing values out.

Despite some the functions in the test already being marked with optnone, adding the MarkAsLive()
calls inside of the pretty printer comparison functions resolves the issues of the values being optimized out.

This patch aims to address https://bugs.llvm.org/show_bug.cgi?id=51675.

Diff Detail

Event Timeline

amyk requested review of this revision.Sep 2 2021, 4:03 PM
amyk created this revision.
Herald added a reviewer: Restricted Project. · View Herald TranscriptSep 2 2021, 4:03 PM
amyk added a comment.Sep 2 2021, 4:05 PM

An example of what occurs when we compile and run the test:

$ clang++ --gcc-toolchain=/usr --target=powerpc64le-unknown-linux-gnu /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp -o /home/amyk/llvm/dev/build/projects/libcxx/test/libcxx/gdb/Output/gdb_pretty_printer_test.sh.cpp.dir/t.tmp.exe -include /home/amyk/llvm/dev/llvm-project/libcxx/test/support/nasty_macros.h -nostdinc++ -I/home/amyk/llvm/dev/build/include/c++/v1 -I/home/amyk/llvm/dev/build/projects/libcxx/include/c++build -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -I/home/amyk/llvm/dev/llvm-project/libcxx/test/support -std=c++20 -Werror -Wall -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_DISABLE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -Wno-macro-redefined -D_LIBCPP_HAS_THREAD_API_PTHREAD -Wno-macro-redefined -D_LIBCPP_ABI_VERSION=1  -g -lc++experimental -L/home/amyk/llvm/dev/build/./lib -Wl,-rpath,/home/amyk/llvm/dev/build/./lib -L/home/amyk/llvm/dev/build/./lib -Wl,-rpath,/home/amyk/llvm/dev/build/./lib -nodefaultlibs -lc++ -lm -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc -latomic

$ "/usr/bin/gdb" "-nx" "-batch" "-iex" "set autoload off" "-ex" "source /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/../../../utils/gdb/libcxx/printers.py" "-ex" "python register_libcxx_printer_loader()" "-ex" "source /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py" "/home/amyk/llvm/dev/build/projects/libcxx/test/libcxx/gdb/Output/gdb_pretty_printer_test.sh.cpp.dir/t.tmp.exe"
No symbol table is loaded.  Use the "file" command.
Breakpoint 1 at 0x10002968: file llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp, line 67.
Loading libc++ pretty-printers.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/power9/libthread_db.so.1".
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:170
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:174
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:179
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:184

. . . 

PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:648
[Inferior 1 (process 708433) exited normally]
FAILED 82 cases

After adding the MarkAsLive() calls:

$ /usr/bin/gdb -nx -batch -iex "set autoload off" -ex "source /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/../../../utils/gdb/libcxx/printers.py" -ex "python register_libcxx_printer_loader()" -ex "source /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py" /home/amyk/llvm/dev/build/projects/libcxx/test/libcxx/gdb/Output/gdb_pretty_printer_test.sh.cpp.dir/t.tmp.exe
No symbol table is loaded.  Use the "file" command.
Breakpoint 1 at 0x10002968: file /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp, line 67.
Loading libc++ pretty-printers.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/power9/libthread_db.so.1".
PASS: /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:154
PASS: /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:158

. . . 

PASS: /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:652
[Inferior 1 (process 2898308) exited normally]

$ echo $?
0
saugustine accepted this revision.Sep 2 2021, 4:07 PM
ldionne accepted this revision.Sep 3 2021, 11:53 AM
This revision is now accepted and ready to land.Sep 3 2021, 11:53 AM

Cherry-picked onto release/13.x as

commit 1c3fcc8ae92ebfe9a9d1a21a288ad71ef7f98091 (HEAD -> release/13.x)
Author: Amy Kwan <amy.kwan1@ibm.com>
Date:   Fri Sep 3 14:53:57 2021 -0400

    [libc++][NFC] Mark values in gdb pretty print comparison functions as live to prevent values being optimized out.

    It appears when testing LLVM 13 on Power, we run into failures with the
    `libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp` test case optimizing
    values out.

    Despite some the functions in the test already being marked with optnone,
    adding the `MarkAsLive()` calls inside of the pretty printer comparison functions
    resolves the issues of the values being optimized out.

    This patch aims to address https://llvm.org/PR51675.

    Differential Revision: https://reviews.llvm.org/D109204

    (cherry picked from commit 217c6d643124be312f4a99b203118744edb9d54c)