LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 37652 - Can't use EXPENSIVE_CHECKS in TableGen executable
Summary: Can't use EXPENSIVE_CHECKS in TableGen executable
Status: RESOLVED FIXED
Alias: None
Product: tools
Classification: Unclassified
Component: TableGen (show other bugs)
Version: trunk
Hardware: All Linux
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-01 06:05 PDT by Andrew V. Tischenko
Modified: 2021-03-10 15:18 PST (History)
7 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew V. Tischenko 2018-06-01 06:05:28 PDT
When I build TableGen with EXPENSIVE_CHECKS defined the executable crashes inside llvm::sort during its invocation from CodeGenIntrinsicTable::CodeGenIntrinsicTable
Comment 1 Simon Pilgrim 2018-06-03 04:14:42 PDT
Andrew, with what OS and compiler are you seeing this?
Comment 2 Andrew V. Tischenko 2018-06-05 01:14:43 PDT
Linux, standart Clang toolchain like here:

atischenko@ip-172-31-21-62:~/workspaces$ cat new-workspace-avt77-make.sh

mkdir build
svn co https://avt77@llvm.org/svn/llvm-project/llvm/trunk llvm
cd llvm/tools
svn co https://avt77@llvm.org/svn/llvm-project/cfe/trunk clang
cd ../../build
cmake -DLLVM_ENABLE_EXPENSIVE_CHECKS -DCMAKE_BUILD_TYPE=Debug ../llvm
cmake -E time make -j 4

The last line creates TableGen and trys to use it but can't because of the issue.
Comment 3 Simon Pilgrim 2018-06-05 02:03:37 PDT
So you're building with gcc? What version?

Also, please can you include the error message you see from the Tablegen build.
Comment 4 Andrew V. Tischenko 2018-06-05 03:50:41 PDT
Yes, I used gcc to create TableGe. I'll give you all necessary info asap.
Comment 5 Andrew V. Tischenko 2018-06-05 03:57:58 PDT
-- The CXX compiler identification is GNU 5.4.0
Comment 6 Andrew V. Tischenko 2018-06-05 04:19:49 PDT
And now I got the following:

Scanning dependencies of target LibOptionsTableGen
[ 23%] Building Options.inc...
[ 23%] Building Options.inc...
[ 23%] Building Intrinsics.inc...
[ 23%] Updating Options.inc...
[ 23%] Updating Options.inc...
[ 23%] Built target DllOptionsTableGen
[ 23%] Built target LibOptionsTableGen
Scanning dependencies of target clang-tablegen-targets
[ 23%] Built target clang-tablegen-targets
Scanning dependencies of target llvm-mt
[ 23%] Building CXX object tools/llvm-mt/CMakeFiles/llvm-mt.dir/llvm-mt.cpp.o
Scanning dependencies of target llvm-rc
[ 23%] Building CXX object tools/llvm-rc/CMakeFiles/llvm-rc.dir/llvm-rc.cpp.o
[ 23%] Updating Options.inc...
[ 23%] Built target ClangDriverOptions
[ 23%] Building CXX object tools/llvm-rc/CMakeFiles/llvm-rc.dir/ResourceFileWriter.cpp.o
/usr/include/c++/5/debug/safe_container.h:86:error: attempt to self move
    assign.

Objects involved in the operation:
sequence "this" @ 0x0x7ffbdc9c6288 {
}
../../../bin/llvm-tblgen[0x9a1271]
../../../bin/llvm-tblgen[0x9a1304]
../../../bin/llvm-tblgen[0x99f544]
../../../bin/llvm-tblgen[0x9a0c87]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7ffbddb79390]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x38)[0x7ffbdcd0a428]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x16a)[0x7ffbdcd0c02a]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZNK11__gnu_debug16_Error_formatter8_M_errorEv+0x155)[0x7ffbdd672f95]
../../../bin/llvm-tblgen[0x64dd86]
../../../bin/llvm-tblgen[0x64a7b5]
../../../bin/llvm-tblgen[0x64a815]
../../../bin/llvm-tblgen[0x64a99c]
../../../bin/llvm-tblgen[0x64ab02]
../../../bin/llvm-tblgen[0x6463b7]
../../../bin/llvm-tblgen[0x64156f]
../../../bin/llvm-tblgen[0x633d83]
../../../bin/llvm-tblgen[0x630a8d]
../../../bin/llvm-tblgen[0x7c0a1a]
../../../bin/llvm-tblgen[0x7c4581]
../../../bin/llvm-tblgen[0x89b258]
../../../bin/llvm-tblgen[0x9dcb77]
../../../bin/llvm-tblgen[0x89b918]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7ffbdccf5830]
../../../bin/llvm-tblgen[0x4096e9]
Stack dump:
0.      Program arguments: ../../../bin/llvm-tblgen -gen-intrinsic -I /home/atischenko/workspaces/pr35548-tg-warns/llvm/include/llvm/IR -I /home/atischenko/workspaces/pr35548-tg-warns/llvm/include /home/atischenko/workspaces/pr35548-tg-warns/llvm/include/llvm/IR/Intrinsics.td -o /home/atischenko/workspaces/pr35548-tg-warns/build/include/llvm/IR/Intrinsics.inc.tmp
Aborted (core dumped)
include/llvm/IR/CMakeFiles/intrinsics_gen.dir/build.make:161: recipe for target 'include/llvm/IR/Intrinsics.inc.tmp' failed
make[2]: *** [include/llvm/IR/Intrinsics.inc.tmp] Error 134
CMakeFiles/Makefile2:976: recipe for target 'include/llvm/IR/CMakeFiles/intrinsics_gen.dir/all' failed
make[1]: *** [include/llvm/IR/CMakeFiles/intrinsics_gen.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 23%] Building CXX object tools/llvm-rc/CMakeFiles/llvm-rc.dir/ResourceScriptCppFilter.cpp.o
[ 23%] Linking CXX executable ../../bin/llvm-mt
[ 23%] Building CXX object tools/llvm-rc/CMakeFiles/llvm-rc.dir/ResourceScriptParser.cpp.o
[ 23%] Built target llvm-mt
[ 23%] Building CXX object tools/llvm-rc/CMakeFiles/llvm-rc.dir/ResourceScriptStmt.cpp.o
[ 23%] Building CXX object tools/llvm-rc/CMakeFiles/llvm-rc.dir/ResourceScriptToken.cpp.o
[ 23%] Linking CXX executable ../../bin/llvm-rc
[ 23%] Built target llvm-rc
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2

With gdb I saw usage of sort but I'm not sure it's a sort problem. Most probably there is an attempt to use destructed objects inside sort. Not long ago I had the very similar problem when I tried to sort FunctionDecl* objects to print out the compilation times.
Comment 7 Simon Pilgrim 2018-06-05 05:52:07 PDT
@mgrang is this something you've seen at all?
Comment 8 Mandeep Singh Grang 2018-06-05 15:50:45 PDT
I haven't seen this in my testing. However, I can reproduce the failure using the steps Andrew provided.

It seems the crash is coming out of this particular instance of llvm:sort in utils/TableGen/CodeGenTarget.cpp:

CodeGenIntrinsicTable::CodeGenIntrinsicTable(const RecordKeeper &RC,
                                             bool TargetOnly) {
...

  llvm::sort(Intrinsics.begin(), Intrinsics.end(),
             [](const CodeGenIntrinsic &LHS, const CodeGenIntrinsic &RHS) {
               return std::tie(LHS.TargetPrefix, LHS.Name) <
                      std::tie(RHS.TargetPrefix, RHS.Name);
...
}

I didn't get a chance to look into this more closely but if I remove the comparator then it seems to go fine.
Comment 9 Andrew V. Tischenko 2018-06-06 06:27:22 PDT
What does default comparator do? Simply compares 2 pointers? If yes it means it does not deal with underlying objects and that looks very similar to what I saw with FunctionDecl* pointers (see above).
Comment 10 Andrew V. Tischenko 2018-07-17 02:15:11 PDT
*** Bug 38172 has been marked as a duplicate of this bug. ***
Comment 11 Alexander Richardson 2019-02-19 05:09:17 PST
According to https://stackoverflow.com/questions/22915325/avoiding-self-assignment-in-stdshuffle this is caused by an overly aggressive assertion in libstdc++.

I just tried copying the libc++ of std::shuffle() as llvm::shuffle() and using that instead and it appears to fix the problem. If this is considered a reasonable solution I can upload a patch to phabricator.
Comment 12 Simon Pilgrim 2019-02-19 12:58:10 PST
(In reply to Alexander Richardson from comment #11)
> According to
> https://stackoverflow.com/questions/22915325/avoiding-self-assignment-in-
> stdshuffle this is caused by an overly aggressive assertion in libstdc++.
> 
> I just tried copying the libc++ of std::shuffle() as llvm::shuffle() and
> using that instead and it appears to fix the problem. If this is considered
> a reasonable solution I can upload a patch to phabricator.

Yes thank you, I think that its worth raising as a patch to be discussed by a broader audience.
Comment 13 Nikita Popov 2021-03-08 02:38:25 PST
This issue still exists.
Comment 14 Alexander Richardson 2021-03-08 03:48:52 PST
Possible fix https://reviews.llvm.org/D98167
Comment 15 Alexander Richardson 2021-03-10 15:18:12 PST
Should be fixed by https://github.com/llvm/llvm-project/commit/35bf23e965508a6ca00009ca45ba882d1ba7808c