Thread: clang warning: -Watomic-implicit-seq-cst

  1. #1
    Registered User
    Join Date
    Mar 2020
    Posts
    15

    clang warning: -Watomic-implicit-seq-cst

    I have this piece of code:

    Code:
    atomic_int Vector[2];
    
    void Load(int *v)
    {
       v[0]=atomic_load(&Vector[0]);
       v[1]=atomic_load(&Vector[1]);
    }
    
    void Store(int *v)
    {
       atomic_store(&Vector[0],v[0]);
       atomic_store(&Vector[1],v[1]);
    }
    clang give this warning: implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary.
    How can this warning be solved?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You need to be more specific.
    Code:
    #include <stdatomic.h>
    
    atomic_int Vector[2];
     
    void Load(int *v)
    {
       v[0]=atomic_load(&Vector[0]);
       v[1]=atomic_load(&Vector[1]);
    }
     
    void Store(int *v)
    {
       atomic_store(&Vector[0],v[0]);
       atomic_store(&Vector[1],v[1]);
    }
    
    int main()
    {
        return 0;
    }
    I tried this over on Compiler Explorer for several versions of clang with several sets of flags and saw nothing unusual.

    State:
    - your actual clang version
    - your actual compiler command line
    - your actual compilable program (not some snippet)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2020
    Posts
    15
    Ok, this is the code for compiler explorer try with flag -Weverything

    Code:
    #include <stdatomic.h>
    
    
    typedef struct
    {
       atomic_ullong V[2];
    } vector_t;
    
    vector_t *Vector;
    
    
    void Load(int index,vector_t *vec)
    {  
       vec->V[0] = atomic_load(&Vector[index].V[0]);
       vec->V[1] = atomic_load(&Vector[index].V[1]);
       vec->V[0]^=vec->V[1];
    }
    
    
    void Store(int index,vector_t *vec)
    {  
       vec->V[0]^=vec->V[1];
       atomic_store(&Vector[index].V[0],vec->V[0]);
       atomic_store(&Vector[index].V[1],vec->V[1]);
    }
    
    
    

  4. #4
    Registered User
    Join Date
    Mar 2020
    Posts
    15
    I have solved in this way:

    Code:
    #include <stdatomic.h>
    
    typedef struct
    {
       atomic_ullong V[2];
    } vectoratomic_t;
    
    typedef struct
    {
        unsigned long long int V[2];
    } vector_t;
    
    vectoratomic_t *Vector;
    
    void Load(int index,vector_t *vec)
    {  
       vec->V[0] = atomic_load(&Vector[index].V[0]);
       vec->V[1] = atomic_load(&Vector[index].V[1]);
       vec->V[0]^=vec->V[1];
    }
    
    void Store(int index,vector_t *vec)
    {  
       vec->V[0]^=vec->V[1];
       atomic_store(&Vector[index].V[0],vec->V[0]);
      atomic_store(&Vector[index].V[1],vec->V[1]);
    }
    
    I'm sorry for the question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with timersub(), implicit declaration warning!
    By confundido in forum C Programming
    Replies: 8
    Last Post: 09-30-2020, 07:16 PM
  2. implicit declaration of function warning
    By cooper1200 in forum C Programming
    Replies: 3
    Last Post: 04-27-2019, 04:25 AM
  3. gcc warning: implicit declaration of function
    By anatoly in forum C Programming
    Replies: 4
    Last Post: 05-02-2010, 04:32 PM
  4. Replies: 4
    Last Post: 07-22-2007, 08:17 PM
  5. Implicit Declaration Warning
    By robosapien in forum C Programming
    Replies: 5
    Last Post: 04-02-2007, 08:35 PM

Tags for this Thread