@@ -876,3 +876,45 @@ predicate getAThreadSpecificStorageDeallocationCall(C11ThreadCreateCall tcc, Dea
876876 DataFlow:: localFlow ( DataFlow:: exprNode ( tsg ) , DataFlow:: exprNode ( dexp .getFreedExpr ( ) ) )
877877 )
878878}
879+
880+ /**
881+ * Models calls to routines `atomic_compare_exchange_weak` and
882+ * `atomic_compare_exchange_weak_explicit` in the `stdatomic` library.
883+ * Note that these are typically implemented as macros within Clang and
884+ * GCC's standard libraries.
885+ */
886+ class AtomicCompareExchange extends MacroInvocation {
887+ AtomicCompareExchange ( ) {
888+ getMacroName ( ) = "atomic_compare_exchange_weak"
889+ or
890+ // some compilers model `atomic_compare_exchange_weak` as a macro that
891+ // expands to `atomic_compare_exchange_weak_explicit` so this defeats that
892+ // and other similar modeling.
893+ getMacroName ( ) = "atomic_compare_exchange_weak_explicit" and
894+ not exists ( MacroInvocation m |
895+ m .getMacroName ( ) = "atomic_compare_exchange_weak" and
896+ m .getAnExpandedElement ( ) = getAnExpandedElement ( )
897+ )
898+ }
899+ }
900+
901+ /**
902+ * Models calls to routines `atomic_store` and
903+ * `atomic_store_explicit` in the `stdatomic` library.
904+ * Note that these are typically implemented as macros within Clang and
905+ * GCC's standard libraries.
906+ */
907+ class AtomicStore extends MacroInvocation {
908+ AtomicStore ( ) {
909+ getMacroName ( ) = "atomic_store"
910+ or
911+ // some compilers model `atomic_compare_exchange_weak` as a macro that
912+ // expands to `atomic_compare_exchange_weak_explicit` so this defeats that
913+ // and other similar modeling.
914+ getMacroName ( ) = "atomic_store_explicit" and
915+ not exists ( MacroInvocation m |
916+ m .getMacroName ( ) = "atomic_store" and
917+ m .getAnExpandedElement ( ) = getAnExpandedElement ( )
918+ )
919+ }
920+ }
0 commit comments