Skip to content

Conversation

@d7d1cd
Copy link

@d7d1cd d7d1cd commented Nov 4, 2025

Solve this issue #164216

@github-actions
Copy link

github-actions bot commented Nov 4, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Nov 4, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Sergey Chebotarev (d7d1cd)

Changes

Solve this issue #164216


Full diff: https://github.com/llvm/llvm-project/pull/166399.diff

1 Files Affected:

  • (modified) compiler-rt/include/sanitizer/tsan_interface.h (+11-11)
diff --git a/compiler-rt/include/sanitizer/tsan_interface.h b/compiler-rt/include/sanitizer/tsan_interface.h
index e11a4175cd8ed..dae075106426f 100644
--- a/compiler-rt/include/sanitizer/tsan_interface.h
+++ b/compiler-rt/include/sanitizer/tsan_interface.h
@@ -38,39 +38,39 @@ void SANITIZER_CDECL __tsan_release(void *addr);
 
 // Mutex has static storage duration and no-op constructor and destructor.
 // This effectively makes tsan ignore destroy annotation.
-static const unsigned __tsan_mutex_linker_init      = 1 << 0;
+inline constexpr unsigned __tsan_mutex_linker_init      = 1 << 0;
 // Mutex is write reentrant.
-static const unsigned __tsan_mutex_write_reentrant  = 1 << 1;
+inline constexpr unsigned __tsan_mutex_write_reentrant  = 1 << 1;
 // Mutex is read reentrant.
-static const unsigned __tsan_mutex_read_reentrant   = 1 << 2;
+inline constexpr unsigned __tsan_mutex_read_reentrant   = 1 << 2;
 // Mutex does not have static storage duration, and must not be used after
 // its destructor runs.  The opposite of __tsan_mutex_linker_init.
 // If this flag is passed to __tsan_mutex_destroy, then the destruction
 // is ignored unless this flag was previously set on the mutex.
-static const unsigned __tsan_mutex_not_static       = 1 << 8;
+inline constexpr unsigned __tsan_mutex_not_static       = 1 << 8;
 
 // Mutex operation flags:
 
 // Denotes read lock operation.
-static const unsigned __tsan_mutex_read_lock = 1 << 3;
+inline constexpr unsigned __tsan_mutex_read_lock = 1 << 3;
 // Denotes try lock operation.
-static const unsigned __tsan_mutex_try_lock = 1 << 4;
+inline constexpr unsigned __tsan_mutex_try_lock = 1 << 4;
 // Denotes that a try lock operation has failed to acquire the mutex.
-static const unsigned __tsan_mutex_try_lock_failed = 1 << 5;
+inline constexpr unsigned __tsan_mutex_try_lock_failed = 1 << 5;
 // Denotes that the lock operation acquires multiple recursion levels.
 // Number of levels is passed in recursion parameter.
 // This is useful for annotation of e.g. Java builtin monitors,
 // for which wait operation releases all recursive acquisitions of the mutex.
-static const unsigned __tsan_mutex_recursive_lock = 1 << 6;
+inline constexpr unsigned __tsan_mutex_recursive_lock = 1 << 6;
 // Denotes that the unlock operation releases all recursion levels.
 // Number of released levels is returned and later must be passed to
 // the corresponding __tsan_mutex_post_lock annotation.
-static const unsigned __tsan_mutex_recursive_unlock = 1 << 7;
+inline constexpr unsigned __tsan_mutex_recursive_unlock = 1 << 7;
 
 // Convenient composed constants.
-static const unsigned __tsan_mutex_try_read_lock =
+inline constexpr unsigned __tsan_mutex_try_read_lock =
     __tsan_mutex_read_lock | __tsan_mutex_try_lock;
-static const unsigned __tsan_mutex_try_read_lock_failed =
+inline constexpr unsigned __tsan_mutex_try_read_lock_failed =
     __tsan_mutex_try_read_lock | __tsan_mutex_try_lock_failed;
 
 // Annotate creation of a mutex.

@pinskia
Copy link

pinskia commented Nov 4, 2025

I am not sure if this works with C or C++11.

@vitalybuka vitalybuka self-requested a review November 5, 2025 01:26
Copy link
Collaborator

@vitalybuka vitalybuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header should be C compatible

enum maybe?

@d7d1cd
Copy link
Author

d7d1cd commented Nov 5, 2025

@vitalybuka, thanks for the suggestion to use enum.
@pinskia, I think the code now satisfies the requirement to work in C.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants