This is an archive of the discontinued LLVM Phabricator instance.

Build fix: Turn off _GLIBCXX_DEBUG on gcc 9
ClosedPublic

Authored by nhaehnle on Feb 26 2020, 10:51 AM.

Details

Summary

Enabling _GLIBCXX_DEBUG (implied by LLVM_ENABLE_EXPENSIVE_CHECKS) causes
std::min (and presumably others) to no longer be constexpr, which in turn
causes the build to fail.

This seems like a bug in the GCC STL. This change works around it.

Change-Id: I5fc471caa9c4de3ef4e87aeeac8df1b960e8e72c

Diff Detail

Event Timeline

nhaehnle created this revision.Feb 26 2020, 10:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 26 2020, 10:51 AM
Herald added a subscriber: mgorny. · View Herald Transcript
hans added a comment.Feb 26 2020, 10:57 AM

What happens if one uses libstdc++ 9 but with Clang?

Thanks for working on this! I ran into this once and manually undefined the macro, so the workaround looks decent. However, I share @hans concerns about the detection part. You most likely want to compile minimal C++ program using std::min (and maybe other functions) to detect if the actual standard library used matches our requirements.

jwakely added a comment.EditedFeb 27 2020, 1:25 AM

I think this affects the versions of std::min(std::initializer_list) and std::max(std::initializer_list), and std::{min,max,minmax}_element. It's already fixed for GCC 10.

Testing for GCC is definitely wrong, it needs to test for the library. If __GLIBCXX__ is defined then you're using libstdc++, and for versions since 7.1.0 _GLIBCXX_RELEASE tells you the release version, so you can use that to detect libstdc++ from GCC 10.

P.S. you could use _GLIBCXX_ASSERTIONS instead for affected versions of libstdc++. That is a subset of _GLIBCXX_DEBUG that has far fewer checks, but is still much better than not checking anything at all.

@nhaehnle : something like

CHECK_CXX_SOURCE_COMPILES("
#define _GLIBCXX_DEBUG
#include <algorithm>

int main(int argc, char ** argv) {
    static constexpr int data []= {0, 1};
    constexpr const int* min_elt  = std::min_element(&data[0], &data[2]) ;
    return 0;
}" CXX_SUPPORTS_GLIBCXX8DEBUG)
nhaehnle updated this revision to Diff 247506.Mar 1 2020, 8:12 AM

Thank you all for the advice.

Changing the patch to use a compile check and fall back to
_GLIBCXX_ASSERTIONS.

This revision is now accepted and ready to land.Mar 2 2020, 6:46 AM
This revision was automatically updated to reflect the committed changes.