Skip to content

Linux compiler error #729

Closed
Closed

Description

/data/src/mimalloc/v2.1.1$ uname -a
Linux dev 5.15.49-linuxkit #1 SMP Tue Sep 13 07:51:46 UTC 2022 x86_64 GNU/Linux

/data/src/mimalloc/v2.1.1$ clang --version
Debian clang version 15.0.7
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
/usr/bin/clang++ -DMI_MALLOC_OVERRIDE -I/tmp/v2.1.1/include -O3 -DNDEBUG -fPIC -Wno-deprecated -Wall -Wextra -Wno-unknown-pragmas -fvisibility=hidden -Wpedantic -Wno-static-in-inline -ftls-model=initial-exec -fno-builtin-malloc -std=gnu++17 -MD -MT CMakeFiles/mimalloc-obj.dir/src/static.c.o -MF CMakeFiles/mimalloc-obj.dir/src/static.c.o.d -o CMakeFiles/mimalloc-obj.dir/src/static.c.o -c /tmp/v2.1.1/src/static.c
In file included from /tmp/v2.1.1/src/static.c:17:
In file included from /tmp/v2.1.1/include/mimalloc/internal.h:17:
In file included from /tmp/v2.1.1/include/mimalloc/types.h:24:
/tmp/v2.1.1/include/mimalloc/atomic.h:284:10: error: no matching function for call to 'atomic_compare_exchange_strong_explicit'
  return mi_atomic_cas_strong_acq_rel(once, &expected, 1); // try to set to 1
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/v2.1.1/include/mimalloc/atomic.h:61:50: note: expanded from macro 'mi_atomic_cas_strong_acq_rel'
#define mi_atomic_cas_strong_acq_rel(p,exp,des)  mi_atomic_cas_strong(p,exp,des,mi_memory_order(acq_rel),mi_memory_order(acquire))
                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/v2.1.1/include/mimalloc/atomic.h:50:3: note: expanded from macro 'mi_atomic_cas_strong'
  mi_atomic(compare_exchange_strong_explicit)(p,expected,desired,mem_success,mem_fail)
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/v2.1.1/include/mimalloc/atomic.h:24:33: note: expanded from macro 'mi_atomic'
#define  mi_atomic(name)        std::atomic_##name
                                ^~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/atomic:1123:5: note: candidate template ignored: deduced conflicting types for parameter '_ITp' ('unsigned long' vs. 'int')
    atomic_compare_exchange_strong_explicit(atomic<_ITp>* __a,
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/atomic:1131:5: note: candidate template ignored: deduced conflicting types for parameter '_ITp' ('unsigned long' vs. 'int')
    atomic_compare_exchange_strong_explicit(volatile atomic<_ITp>* __a,
    ^

Activity

  1. davide-digennaro-nozomi commented on Apr 14, 2023

    @davide-digennaro-nozomi
    Author

    It appears that this particular standard library uses an improper function.
    Instead of

    template< class T >
    bool atomic_compare_exchange_strong_explicit( std::atomic<T>* obj,
                                                typename std::atomic<T>::value_type* expected,
                                                typename std::atomic<T>::value_type desired, ...
    

    it has

      template<typename _ITp>
        inline bool
        atomic_compare_exchange_strong_explicit(atomic<_ITp>* __a,
                                                _ITp* __i1, _ITp __i2, ...
    

    so you actually need to explicitly cast the third argument to make it work, e.g.:

      return mi_atomic_cas_strong_acq_rel(once, &expected, (uintptr_t)1); // try to set to 1
    
  2. daanx commented on Apr 14, 2023

    @daanx
    Collaborator

    Thanks so much for the report! I think it is fixed now.

  3. davide-digennaro-nozomi commented on Apr 17, 2023

    @davide-digennaro-nozomi
    Author

    please, note that the fix here may not be enough, as it depends on how precisely uintptr_t is defined (in fact, in some platforms it won't work at all, as it would require 1ULL, not 1UL).
    the bulletproof fix is the one I mentioned above.

  4. daanx commented on Apr 17, 2023

    @daanx
    Collaborator

    Thanks! I pushed a fix again :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions