Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • G GLib
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 858
    • Issues 858
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 57
    • Merge requests 57
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GNOMEGNOME
  • GLib
  • Merge requests
  • !1006

gatomic: Fix false positive with Clang+TSAN

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Peter Wu requested to merge Lekensteyn/glib:1843-tsan-atomic-clang-fix into master Jul 26, 2019
  • Overview 4
  • Commits 1
  • Pipelines 3
  • Changes 2

__atomic_load_8 and friends do not exist under clang. Use the generic __atomic_load variant instead that are documented here: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html

These have the additional benefit that the exact size of gint (4 bytes) or gpointer (4 or 8 bytes) no longer have to be checked.

I initially tried __typeof__(*(atomic)) val;, but that caused warnings in Clang (-Wincompatible-pointer-types-discards-qualifiers) when "atomic" points to a volatile variable. Aside from that, it is apparently not supported everywhere, see the g_has_typeof macro. Another reason not to use it are new warnings under Clang, including:

glib/deprecated/gthread-deprecated.c:683:11: warning: incompatible pointer types initializing 'typeof (*(&mutex->mutex.mutex))' (aka 'union _GMutex *') with an expression of type 'GRecMutex *' (aka 'struct _GRecMutex *') [-Wincompatible-pointer-types]
          g_atomic_pointer_set (&mutex->mutex.mutex, result);

Hence, cast the atomic variable to gint/gpointer pointers, the size was already statically asserted so the cast should be safe.

Closes #1843 (closed)


Clang now passes the glib/tests/atomic test which GCC was already able to do. I have not executed a full test suite run yet, hopefully CI can do that for me.

Edited Jul 26, 2019 by Peter Wu
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: 1843-tsan-atomic-clang-fix