Commit Graph

21 Commits

Author SHA1 Message Date
Eric Fiselier fc26379a84 [libc++] Introduce _LIBCPP_EXTERN_VIS to fix __libcpp_debug_function link errors
Summary: On Windows tests that use `_LIBCPP_ASSERT` fail to link because the assertion handler function isn't correctly exported from the libc++ dylib. This patch fixes the dll import/export issues by introducing a new visibility macro `_LIBCPP_EXTERN_VIS` for use on external variables.

Reviewers: compnerd, smeenai, EricWF

Reviewed By: EricWF

Subscribers: cfe-commits

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

llvm-svn: 292158
2017-01-16 21:01:00 +00:00
Eric Fiselier 8f56dedb5f Replace _LIBCPP_HAS_NO_DELETED_FUNCTIONS with _LIBCPP_CXX03_LANG
llvm-svn: 291278
2017-01-06 20:58:25 +00:00
Eric Fiselier e2f2d1edef [NFC] Rename _LIBCPP_TYPE_VIS_ONLY to _LIBCPP_TEMPLATE_VIS
The name _LIBCPP_TYPE_VIS_ONLY is no longer accurate because both
_LIBCPP_TYPE_VIS and _LIBCPP_TYPE_VIS_ONLY expand to
__attribute__((__type_visibility__)) with Clang. The only remaining difference
is that _LIBCPP_TYPE_VIS_ONLY can be applied to templates whereas
_LIBCPP_TYPE_VIS cannot (due to dllimport/dllexport not being allowed on
templates).

This patch renames _LIBCPP_TYPE_VIS_ONLY to _LIBCPP_TEMPLATE_VIS.

llvm-svn: 291035
2017-01-04 23:56:00 +00:00
Eric Fiselier d5ae0257f2 Ensure <__debug> gets the nullptr definition in C++03
llvm-svn: 290658
2016-12-28 06:15:01 +00:00
Eric Fiselier 8dd73d8e06 Fix stupid build error caused by a stupid person
llvm-svn: 290656
2016-12-28 05:56:16 +00:00
Eric Fiselier c842c8d88c Fix build errors in C++03 caused by recent debug changes
llvm-svn: 290653
2016-12-28 05:26:56 +00:00
Eric Fiselier ab768a85f6 Fix debug mode build w/o exceptions
llvm-svn: 290652
2016-12-28 05:20:27 +00:00
Eric Fiselier 687d3213f0 Implement a throwing version of _LIBCPP_ASSERT.
This patch implements changes to allow _LIBCPP_ASSERT to throw on failure
instead of aborting. The main changes needed to do this are:

1. Change _LIBCPP_ASSERT to call a handler via a replacable function pointer
   instead of calling abort directly. Additionally this patch implements two
   handler functions, one which aborts and another that throws an exception.

2. Add _NOEXCEPT_DEBUG macro for disabling noexcept spec on function which
   contain _LIBCPP_ASSERT. This is required in order to prevent assertion
   failures throwing through a noexcept function. This macro has no effect
   unless _LIBCPP_DEBUG_USE_EXCEPTIONS is defined.

Having a non-aborting _LIBCPP_ASSERT is very important to allow sane testing of
debug mode. Currently we can only have one test case per file, since the test
case will cause the program to abort. Testing debug mode this way would require
thousands of test files, most of which would be 95% boiler plate. I don't think
this is a feasible strategy. Fortunately using a throwing debug handler solves
these issues.

Additionally this patch rewrites the documentation for debug mode.

llvm-svn: 290651
2016-12-28 04:58:52 +00:00
Eric Fiselier 40492ba417 Fix undefined behavior in __hash_table
Summary:
This patch attempts to fix the undefined behavior in __hash_table by changing the node pointer types used throughout. The pointer types are changed for raw pointers in the current ABI and for fancy pointers in ABI V2 (since the fancy pointer types may not be ABI compatible).

The UB in `__hash_table` arises because tree downcasts the embedded end node and then deferences that pointer. Currently there are 2 node types in __hash_table:

* `__hash_node_base` which contains the `__next_` pointer.
* `__hash_node` which contains `__hash_` and `__value_`.

Currently the bucket list, iterators, and `__next_` pointers store pointers to `__hash_node` even though they all need to store `__hash_node_base` pointers.
This patch makes that change by introducing a `__next_pointer` typedef which is a pointer to `__hash_node` in the current ABI and `__hash_node_base` afterwards.

One notable change is to the type of `__bucket_list` which used to be defined as `unique_ptr<__node_pointer[], ...>` and is now `unique_ptr<__next_pointer[], ...>` meaning that we now allocate and deallocate different types using a different allocator. I'm going to give this part of the change more thought since it may introduce compatibility issues.

This change is similar to D20786.



Reviewers: mclow.lists, EricWF

Subscribers: cfe-commits

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

llvm-svn: 276533
2016-07-23 20:36:55 +00:00
Ed Schouten c19393c758 Print log/error messages on stderr, not stdout
There are a couple of places where libc++ prints log/error messages to
stdout on its own. This may of course interfere with the output
generated with applications. Log/error messages should be directed to
stderr instead.

Differential Revision:	http://reviews.llvm.org/D8135
Reviewed by:	marshall

llvm-svn: 231767
2015-03-10 07:57:43 +00:00
Eric Fiselier c1bd9197eb NFC. Move definition of _LIBCPP_ASSERT into __debug header and remove external include guards.
Things done in this patch:

1. Make __debug include __config since it uses macros from it.

2. The current method of defining _LIBCPP_ASSERT is prone to redefinitions. Move
the null _LIBCPP_ASSERT definition into the __debug header to prevent this.

3. Remove external <__debug> include gaurds. <__debug> guards almost all of its
contents internally. There is no reason to be doing it externally.

This patch should not change any functionality.

llvm-svn: 215332
2014-08-10 23:53:08 +00:00
Howard Hinnant fc88dbd298 Debug mode for string. This commit also marks the first time libc++ debug-mode has found a bug (found one in regex). Had to play with extern templates a bit to get this to work since string is heavily used within libc++.dylib.
llvm-svn: 189114
2013-08-23 17:37:05 +00:00
Howard Hinnant 2f51de568f debug mode for unordered_map. Also picked up a missing check and test in unordered_multimap. This wraps up debug mode for the unordered containers.
llvm-svn: 187659
2013-08-02 17:50:49 +00:00
Howard Hinnant 42a3046eef Ok, 3 major changes for debug mode in one commit:
1.  I had been detecting and trapping iterator == and \!= among iterators
    in different containers as an error.  But the trapping itself is actually
    an error.
    
    Consider:
    
    #include <iostream>
    #include <vector>
    #include <algorithm>

    template <class C>
    void
    display(const C& c)
    {
        std::cout << "{";
        bool first = true;
        for (const auto& x : c)
        {
            if (\!first)
                std::cout << ", ";
            first = false;
            std::cout << x;
        }
        std::cout << "}\n";
    }

    int
    main()
    {
        typedef std::vector<int> V;
        V v1 = {1, 3, 5};
        V v2 = {2, 4, 6};
        display(v1);
        display(v2);
        V::iterator i = std::find(v1.begin(), v1.end(), 1);
        V::iterator j = std::find(v2.begin(), v2.end(), 2);
        if (*i == *j)
            i = j;    // perfectly legal
        // ...
        if (i \!= j)   // the only way to check
            v2.push_back(*i);
        display(v1);
        display(v2);
    }

    It is legal to assign an iterator from one container to another of the
    same type.  This is required to work.  One might want to test whether or
    not such an assignment had been made.  The way one performs such a check
    is using the iterator's ==, \!= operator.  This is a logical and necessary
    function and does not constitute an error.

2.  I had a header circular dependence bug when _LIBCPP_DEBUG2 is defined.
    This caused a problem in several of the libc++ tests.
    Fixed.

3.  There is a serious problem when _LIBCPP_DEBUG2=1 at the moment in that
    std::basic_string is inoperable.  std::basic_string uses __wrap_iterator
    to implement its iterators.  __wrap_iterator has been rigged up in debug
    mode to support vector.  But string hasn't been rigged up yet.  This means
    that one gets false positives when using std::string in debug mode.  I've
    upped std::string's priority in www/debug_mode.html.

llvm-svn: 187636
2013-08-02 00:26:35 +00:00
Howard Hinnant 92bd7c0337 Debug mode: learning to crawl. I need to set up some tests that actually test that the debug mode is working, but that won't cause problems when debug mode isn't on. This is my first prototype of such a test. It should call std::terminate() because it's comparing iterators from different containers. And std::terminate() is rigged up to exit normally. If debug mode fails, and doesn't call terminate, then the program asserts. The test is a no-op if _LIBCPP_DEBUG2 is not defined or is defined to be 0.
llvm-svn: 177892
2013-03-25 19:29:35 +00:00
Howard Hinnant 6e41256f68 No functionality change at this time. I've split _LIBCPP_VISIBLE up into two flags: _LIBCPP_TYPE_VIS and _LIBCPP_FUNC_VIS. This is in preparation for taking advantage of clang's new __type_visibility__ attribute.
llvm-svn: 176593
2013-03-06 23:30:19 +00:00
Howard Hinnant c003db1fca Further macro protection by replacing _[A-Z] with _[A-Z]p
llvm-svn: 145410
2011-11-29 18:15:50 +00:00
Howard Hinnant 920b56ca88 Another installment on debug mode. This addresses list. However this should be considered a temporary state. The API of the debug database and how vector and list use it, is unsatisfactory at the moment. It is both inefficient and overly verbose. I wanted to get this functionality checked in though. In the next day or so I'll refactor what is there in an attempt to streamline things.
llvm-svn: 140660
2011-09-27 23:55:03 +00:00
Howard Hinnant c36bfc499b Doug Gregor pointed out some problems with debug mode enabled in one TU and not another. This patch helps detect those situations and offers improved error messages to help get debug mode enabled in more TU's when it is absolutely necessary to do so. Thanks Doug.
llvm-svn: 139933
2011-09-16 19:52:23 +00:00
Howard Hinnant cec9af9ead Create multilevel debug mode
llvm-svn: 139913
2011-09-16 17:29:17 +00:00
Howard Hinnant f554add54e Initial checkin for debug mode (version 2)
llvm-svn: 139711
2011-09-14 18:33:51 +00:00