#define LOCKABLE __attribute__ ((lockable))
#define SCOPED_LOCKABLE __attribute__ ((scoped_lockable))
#define GUARDED_BY(x) __attribute__ ((guarded_by(x)))
#define GUARDED_VAR __attribute__ ((guarded_var))
#define PT_GUARDED_BY(x) __attribute__ ((pt_guarded_by(x)))
#define PT_GUARDED_VAR __attribute__ ((pt_guarded_var))
#define ACQUIRED_AFTER(...) __attribute__ ((acquired_after(__VA_ARGS__)))
#define ACQUIRED_BEFORE(...) __attribute__ ((acquired_before(__VA_ARGS__)))
#define EXCLUSIVE_LOCK_FUNCTION(...) __attribute__ ((exclusive_lock_function(__VA_ARGS__)))
#define SHARED_LOCK_FUNCTION(...) __attribute__ ((shared_lock_function(__VA_ARGS__)))
#define ASSERT_EXCLUSIVE_LOCK(...) __attribute__ ((assert_exclusive_lock(__VA_ARGS__)))
#define ASSERT_SHARED_LOCK(...) __attribute__ ((assert_shared_lock(__VA_ARGS__)))
#define EXCLUSIVE_TRYLOCK_FUNCTION(...) __attribute__ ((exclusive_trylock_function(__VA_ARGS__)))
#define SHARED_TRYLOCK_FUNCTION(...) __attribute__ ((shared_trylock_function(__VA_ARGS__)))
#define UNLOCK_FUNCTION(...) __attribute__ ((unlock_function(__VA_ARGS__)))
#define LOCK_RETURNED(x) __attribute__ ((lock_returned(x)))
#define LOCKS_EXCLUDED(...) __attribute__ ((locks_excluded(__VA_ARGS__)))
#define EXCLUSIVE_LOCKS_REQUIRED(...) \
__attribute__ ((exclusive_locks_required(__VA_ARGS__)))
#define SHARED_LOCKS_REQUIRED(...) \
__attribute__ ((shared_locks_required(__VA_ARGS__)))
#define NO_THREAD_SAFETY_ANALYSIS __attribute__ ((no_thread_safety_analysis))
class LOCKABLE Mutex {
public:
void Lock() EXCLUSIVE_LOCK_FUNCTION();
void ReaderLock() SHARED_LOCK_FUNCTION();
void Unlock() UNLOCK_FUNCTION();
bool TryLock() EXCLUSIVE_TRYLOCK_FUNCTION(true);
bool ReaderTryLock() SHARED_TRYLOCK_FUNCTION(true);
void AssertHeld() ASSERT_EXCLUSIVE_LOCK();
void AssertReaderHeld() ASSERT_SHARED_LOCK();
};
class UnlockableMu{
};
class MuWrapper {
public:
Mutex mu;
Mutex getMu() {
return mu;
}
Mutex * getMuPointer() {
return μ
}
};
class MuDoubleWrapper {
public:
MuWrapper* muWrapper;
MuWrapper* getWrapper() {
return muWrapper;
}
};
Mutex mu1;
UnlockableMu umu;
Mutex mu2;
MuWrapper muWrapper;
MuDoubleWrapper muDoubleWrapper;
Mutex* muPointer;
Mutex** muDoublePointer = & muPointer;
Mutex& muRef = mu1;
class Foo {
Mutex foomu;
void needLock() EXCLUSIVE_LOCK_FUNCTION(foomu);
};
class Foo2 {
void needLock() EXCLUSIVE_LOCK_FUNCTION(foomu);
Mutex foomu;
};
class Bar {
Mutex barmu;
Mutex barmu2 ACQUIRED_AFTER(barmu);
};
#if !__has_attribute(no_thread_safety_analysis)
#error "Should support no_thread_safety_analysis attribute"
#endif
void noanal_fun() NO_THREAD_SAFETY_ANALYSIS;
void noanal_fun_args() __attribute__((no_thread_safety_analysis(1)));
int noanal_testfn(int y) NO_THREAD_SAFETY_ANALYSIS;
int noanal_testfn(int y) {
int x NO_THREAD_SAFETY_ANALYSIS = y; return x;
};
int noanal_test_var NO_THREAD_SAFETY_ANALYSIS;
class NoanalFoo {
private:
int test_field NO_THREAD_SAFETY_ANALYSIS; void test_method() NO_THREAD_SAFETY_ANALYSIS;
};
class NO_THREAD_SAFETY_ANALYSIS NoanalTestClass { };
void noanal_fun_params(int lvar NO_THREAD_SAFETY_ANALYSIS);
#if !__has_attribute(guarded_var)
#error "Should support guarded_var attribute"
#endif
int gv_var_noargs GUARDED_VAR;
int gv_var_args __attribute__((guarded_var(1)));
class GVFoo {
private:
int gv_field_noargs GUARDED_VAR;
int gv_field_args __attribute__((guarded_var(1))); };
class GUARDED_VAR GV { };
void gv_function() GUARDED_VAR;
void gv_function_params(int gv_lvar GUARDED_VAR);
int gv_testfn(int y){
int x GUARDED_VAR = y; return x;
}
#if !__has_attribute(pt_guarded_var)
#error "Should support pt_guarded_var attribute"
#endif
int *pgv_pt_var_noargs PT_GUARDED_VAR;
int pgv_var_noargs PT_GUARDED_VAR;
class PGVFoo {
private:
int *pt_field_noargs PT_GUARDED_VAR;
int field_noargs PT_GUARDED_VAR; int *gv_field_args __attribute__((pt_guarded_var(1))); };
class PT_GUARDED_VAR PGV { };
int *pgv_var_args __attribute__((pt_guarded_var(1)));
void pgv_function() PT_GUARDED_VAR;
void pgv_function_params(int *gv_lvar PT_GUARDED_VAR);
void pgv_testfn(int y){
int *x PT_GUARDED_VAR = new int(0); delete x;
}
#if !__has_attribute(lockable)
#error "Should support lockable attribute"
#endif
class LOCKABLE LTestClass {
};
class __attribute__((lockable (1))) LTestClass_args { };
void l_test_function() LOCKABLE;
int l_testfn(int y) {
int x LOCKABLE = y; return x;
}
int l_test_var LOCKABLE;
class LFoo {
private:
int test_field LOCKABLE; void test_method() LOCKABLE; };
void l_function_params(int lvar LOCKABLE);
#if !__has_attribute(scoped_lockable)
#error "Should support scoped_lockable attribute"
#endif
class SCOPED_LOCKABLE SLTestClass {
};
class __attribute__((scoped_lockable (1))) SLTestClass_args { };
void sl_test_function() SCOPED_LOCKABLE;
int sl_testfn(int y) {
int x SCOPED_LOCKABLE = y; return x;
}
int sl_test_var SCOPED_LOCKABLE;
class SLFoo {
private:
int test_field SCOPED_LOCKABLE; void test_method() SCOPED_LOCKABLE; };
void sl_function_params(int lvar SCOPED_LOCKABLE);
#if !__has_attribute(guarded_by)
#error "Should support guarded_by attribute"
#endif
int gb_var_arg GUARDED_BY(mu1);
int gb_non_ascii GUARDED_BY(L"wide");
int gb_var_args __attribute__((guarded_by(mu1, mu2)));
int gb_var_noargs __attribute__((guarded_by));
class GBFoo {
private:
int gb_field_noargs __attribute__((guarded_by)); int gb_field_args GUARDED_BY(mu1);
};
class GUARDED_BY(mu1) GB { };
void gb_function() GUARDED_BY(mu1);
void gb_function_params(int gv_lvar GUARDED_BY(mu1));
int gb_testfn(int y){
int x GUARDED_BY(mu1) = y; return x;
}
int gb_var_arg_1 GUARDED_BY(muWrapper.mu);
int gb_var_arg_2 GUARDED_BY(muDoubleWrapper.muWrapper->mu);
int gb_var_arg_3 GUARDED_BY(muWrapper.getMu());
int gb_var_arg_4 GUARDED_BY(*muWrapper.getMuPointer());
int gb_var_arg_5 GUARDED_BY(&mu1);
int gb_var_arg_6 GUARDED_BY(muRef);
int gb_var_arg_7 GUARDED_BY(muDoubleWrapper.getWrapper()->getMu());
int gb_var_arg_8 GUARDED_BY(muPointer);
int gb_var_arg_9 GUARDED_BY(!&mu1);
int gb_var_arg_10 GUARDED_BY(!&*&mu1);
int gb_var_arg_bad_1 GUARDED_BY(1); int gb_var_arg_bad_2 GUARDED_BY("mu"); int gb_var_arg_bad_3 GUARDED_BY(muDoublePointer); int gb_var_arg_bad_4 GUARDED_BY(umu);
#if !__has_attribute(pt_guarded_by)
#error "Should support pt_guarded_by attribute"
#endif
int *pgb_var_noargs __attribute__((pt_guarded_by));
int *pgb_ptr_var_arg PT_GUARDED_BY(mu1);
int *pgb_ptr_var_args __attribute__((pt_guarded_by(mu1, mu2)));
int pgb_var_args PT_GUARDED_BY(mu1);
class PGBFoo {
private:
int *pgb_field_noargs __attribute__((pt_guarded_by)); int *pgb_field_args PT_GUARDED_BY(mu1);
};
class PT_GUARDED_BY(mu1) PGB { };
void pgb_function() PT_GUARDED_BY(mu1);
void pgb_function_params(int gv_lvar PT_GUARDED_BY(mu1));
void pgb_testfn(int y){
int *x PT_GUARDED_BY(mu1) = new int(0); delete x;
}
int * pgb_var_arg_1 PT_GUARDED_BY(muWrapper.mu);
int * pgb_var_arg_2 PT_GUARDED_BY(muDoubleWrapper.muWrapper->mu);
int * pgb_var_arg_3 PT_GUARDED_BY(muWrapper.getMu());
int * pgb_var_arg_4 PT_GUARDED_BY(*muWrapper.getMuPointer());
int * pgb_var_arg_5 PT_GUARDED_BY(&mu1);
int * pgb_var_arg_6 PT_GUARDED_BY(muRef);
int * pgb_var_arg_7 PT_GUARDED_BY(muDoubleWrapper.getWrapper()->getMu());
int * pgb_var_arg_8 PT_GUARDED_BY(muPointer);
int * pgb_var_arg_bad_1 PT_GUARDED_BY(1); int * pgb_var_arg_bad_2 PT_GUARDED_BY("mu"); int * pgb_var_arg_bad_3 PT_GUARDED_BY(muDoublePointer); int * pgb_var_arg_bad_4 PT_GUARDED_BY(umu);
#if !__has_attribute(acquired_after)
#error "Should support acquired_after attribute"
#endif
Mutex mu_aa ACQUIRED_AFTER(mu1);
Mutex aa_var_noargs __attribute__((acquired_after));
class AAFoo {
private:
Mutex aa_field_noargs __attribute__((acquired_after)); Mutex aa_field_args ACQUIRED_AFTER(mu1);
};
class ACQUIRED_AFTER(mu1) AA { };
void aa_function() ACQUIRED_AFTER(mu1);
void aa_function_params(int gv_lvar ACQUIRED_AFTER(mu1));
void aa_testfn(int y){
Mutex x ACQUIRED_AFTER(mu1) = Mutex(); }
Mutex aa_var_arg_1 ACQUIRED_AFTER(muWrapper.mu);
Mutex aa_var_arg_2 ACQUIRED_AFTER(muDoubleWrapper.muWrapper->mu);
Mutex aa_var_arg_3 ACQUIRED_AFTER(muWrapper.getMu());
Mutex aa_var_arg_4 ACQUIRED_AFTER(*muWrapper.getMuPointer());
Mutex aa_var_arg_5 ACQUIRED_AFTER(&mu1);
Mutex aa_var_arg_6 ACQUIRED_AFTER(muRef);
Mutex aa_var_arg_7 ACQUIRED_AFTER(muDoubleWrapper.getWrapper()->getMu());
Mutex aa_var_arg_8 ACQUIRED_AFTER(muPointer);
Mutex aa_var_arg_bad_1 ACQUIRED_AFTER(1); Mutex aa_var_arg_bad_2 ACQUIRED_AFTER("mu"); Mutex aa_var_arg_bad_3 ACQUIRED_AFTER(muDoublePointer); Mutex aa_var_arg_bad_4 ACQUIRED_AFTER(umu); UnlockableMu aa_var_arg_bad_5 ACQUIRED_AFTER(mu_aa);
#if !__has_attribute(acquired_before)
#error "Should support acquired_before attribute"
#endif
Mutex mu_ab ACQUIRED_BEFORE(mu1);
Mutex ab_var_noargs __attribute__((acquired_before));
class ABFoo {
private:
Mutex ab_field_noargs __attribute__((acquired_before)); Mutex ab_field_args ACQUIRED_BEFORE(mu1);
};
class ACQUIRED_BEFORE(mu1) AB { };
void ab_function() ACQUIRED_BEFORE(mu1);
void ab_function_params(int gv_lvar ACQUIRED_BEFORE(mu1));
void ab_testfn(int y){
Mutex x ACQUIRED_BEFORE(mu1) = Mutex(); }
Mutex ab_var_arg_1 ACQUIRED_BEFORE(muWrapper.mu);
Mutex ab_var_arg_2 ACQUIRED_BEFORE(muDoubleWrapper.muWrapper->mu);
Mutex ab_var_arg_3 ACQUIRED_BEFORE(muWrapper.getMu());
Mutex ab_var_arg_4 ACQUIRED_BEFORE(*muWrapper.getMuPointer());
Mutex ab_var_arg_5 ACQUIRED_BEFORE(&mu1);
Mutex ab_var_arg_6 ACQUIRED_BEFORE(muRef);
Mutex ab_var_arg_7 ACQUIRED_BEFORE(muDoubleWrapper.getWrapper()->getMu());
Mutex ab_var_arg_8 ACQUIRED_BEFORE(muPointer);
Mutex ab_var_arg_bad_1 ACQUIRED_BEFORE(1); Mutex ab_var_arg_bad_2 ACQUIRED_BEFORE("mu"); Mutex ab_var_arg_bad_3 ACQUIRED_BEFORE(muDoublePointer); Mutex ab_var_arg_bad_4 ACQUIRED_BEFORE(umu); UnlockableMu ab_var_arg_bad_5 ACQUIRED_BEFORE(mu_ab);
#if !__has_attribute(exclusive_lock_function)
#error "Should support exclusive_lock_function attribute"
#endif
void elf_function() EXCLUSIVE_LOCK_FUNCTION();
void elf_function_args() EXCLUSIVE_LOCK_FUNCTION(mu1, mu2);
int elf_testfn(int y) EXCLUSIVE_LOCK_FUNCTION();
int elf_testfn(int y) {
int x EXCLUSIVE_LOCK_FUNCTION() = y; return x;
};
int elf_test_var EXCLUSIVE_LOCK_FUNCTION();
class ElfFoo {
private:
int test_field EXCLUSIVE_LOCK_FUNCTION(); void test_method() EXCLUSIVE_LOCK_FUNCTION(); };
class EXCLUSIVE_LOCK_FUNCTION() ElfTestClass { };
void elf_fun_params(int lvar EXCLUSIVE_LOCK_FUNCTION());
int elf_function_1() EXCLUSIVE_LOCK_FUNCTION(muWrapper.mu);
int elf_function_2() EXCLUSIVE_LOCK_FUNCTION(muDoubleWrapper.muWrapper->mu);
int elf_function_3() EXCLUSIVE_LOCK_FUNCTION(muWrapper.getMu());
int elf_function_4() EXCLUSIVE_LOCK_FUNCTION(*muWrapper.getMuPointer());
int elf_function_5() EXCLUSIVE_LOCK_FUNCTION(&mu1);
int elf_function_6() EXCLUSIVE_LOCK_FUNCTION(muRef);
int elf_function_7() EXCLUSIVE_LOCK_FUNCTION(muDoubleWrapper.getWrapper()->getMu());
int elf_function_8() EXCLUSIVE_LOCK_FUNCTION(muPointer);
int elf_function_9(Mutex x) EXCLUSIVE_LOCK_FUNCTION(1);
int elf_function_9(Mutex x, Mutex y) EXCLUSIVE_LOCK_FUNCTION(1,2);
int elf_function_bad_2() EXCLUSIVE_LOCK_FUNCTION("mu"); int elf_function_bad_3() EXCLUSIVE_LOCK_FUNCTION(muDoublePointer); int elf_function_bad_4() EXCLUSIVE_LOCK_FUNCTION(umu);
int elf_function_bad_1() EXCLUSIVE_LOCK_FUNCTION(1); int elf_function_bad_5(Mutex x) EXCLUSIVE_LOCK_FUNCTION(0); int elf_function_bad_6(Mutex x, Mutex y) EXCLUSIVE_LOCK_FUNCTION(0); int elf_function_bad_7() EXCLUSIVE_LOCK_FUNCTION(0);
#if !__has_attribute(shared_lock_function)
#error "Should support shared_lock_function attribute"
#endif
void slf_function() SHARED_LOCK_FUNCTION();
void slf_function_args() SHARED_LOCK_FUNCTION(mu1, mu2);
int slf_testfn(int y) SHARED_LOCK_FUNCTION();
int slf_testfn(int y) {
int x SHARED_LOCK_FUNCTION() = y; return x;
};
int slf_test_var SHARED_LOCK_FUNCTION();
void slf_fun_params(int lvar SHARED_LOCK_FUNCTION());
class SlfFoo {
private:
int test_field SHARED_LOCK_FUNCTION(); void test_method() SHARED_LOCK_FUNCTION(); };
class SHARED_LOCK_FUNCTION() SlfTestClass { };
int slf_function_1() SHARED_LOCK_FUNCTION(muWrapper.mu);
int slf_function_2() SHARED_LOCK_FUNCTION(muDoubleWrapper.muWrapper->mu);
int slf_function_3() SHARED_LOCK_FUNCTION(muWrapper.getMu());
int slf_function_4() SHARED_LOCK_FUNCTION(*muWrapper.getMuPointer());
int slf_function_5() SHARED_LOCK_FUNCTION(&mu1);
int slf_function_6() SHARED_LOCK_FUNCTION(muRef);
int slf_function_7() SHARED_LOCK_FUNCTION(muDoubleWrapper.getWrapper()->getMu());
int slf_function_8() SHARED_LOCK_FUNCTION(muPointer);
int slf_function_9(Mutex x) SHARED_LOCK_FUNCTION(1);
int slf_function_9(Mutex x, Mutex y) SHARED_LOCK_FUNCTION(1,2);
int slf_function_bad_2() SHARED_LOCK_FUNCTION("mu"); int slf_function_bad_3() SHARED_LOCK_FUNCTION(muDoublePointer); int slf_function_bad_4() SHARED_LOCK_FUNCTION(umu);
int slf_function_bad_1() SHARED_LOCK_FUNCTION(1); int slf_function_bad_5(Mutex x) SHARED_LOCK_FUNCTION(0); int slf_function_bad_6(Mutex x, Mutex y) SHARED_LOCK_FUNCTION(0); int slf_function_bad_7() SHARED_LOCK_FUNCTION(0);
#if !__has_attribute(exclusive_trylock_function)
#error "Should support exclusive_trylock_function attribute"
#endif
void etf_function() __attribute__((exclusive_trylock_function));
void etf_function_args() EXCLUSIVE_TRYLOCK_FUNCTION(1, mu2);
void etf_function_arg() EXCLUSIVE_TRYLOCK_FUNCTION(1);
int etf_testfn(int y) EXCLUSIVE_TRYLOCK_FUNCTION(1);
int etf_testfn(int y) {
int x EXCLUSIVE_TRYLOCK_FUNCTION(1) = y; return x;
};
int etf_test_var EXCLUSIVE_TRYLOCK_FUNCTION(1);
class EtfFoo {
private:
int test_field EXCLUSIVE_TRYLOCK_FUNCTION(1); void test_method() EXCLUSIVE_TRYLOCK_FUNCTION(1); };
class EXCLUSIVE_TRYLOCK_FUNCTION(1) EtfTestClass { };
void etf_fun_params(int lvar EXCLUSIVE_TRYLOCK_FUNCTION(1));
int etf_function_1() EXCLUSIVE_TRYLOCK_FUNCTION(1, muWrapper.mu);
int etf_function_2() EXCLUSIVE_TRYLOCK_FUNCTION(1, muDoubleWrapper.muWrapper->mu);
int etf_function_3() EXCLUSIVE_TRYLOCK_FUNCTION(1, muWrapper.getMu());
int etf_function_4() EXCLUSIVE_TRYLOCK_FUNCTION(1, *muWrapper.getMuPointer());
int etf_function_5() EXCLUSIVE_TRYLOCK_FUNCTION(1, &mu1);
int etf_function_6() EXCLUSIVE_TRYLOCK_FUNCTION(1, muRef);
int etf_function_7() EXCLUSIVE_TRYLOCK_FUNCTION(1, muDoubleWrapper.getWrapper()->getMu());
int etf_functetfn_8() EXCLUSIVE_TRYLOCK_FUNCTION(1, muPointer);
int etf_function_9() EXCLUSIVE_TRYLOCK_FUNCTION(true);
int etf_function_bad_1() EXCLUSIVE_TRYLOCK_FUNCTION(mu1); int etf_function_bad_2() EXCLUSIVE_TRYLOCK_FUNCTION("mu"); int etf_function_bad_3() EXCLUSIVE_TRYLOCK_FUNCTION(muDoublePointer);
int etf_function_bad_4() EXCLUSIVE_TRYLOCK_FUNCTION(1, "mu"); int etf_function_bad_5() EXCLUSIVE_TRYLOCK_FUNCTION(1, muDoublePointer); int etf_function_bad_6() EXCLUSIVE_TRYLOCK_FUNCTION(1, umu);
#if !__has_attribute(shared_trylock_function)
#error "Should support shared_trylock_function attribute"
#endif
void stf_function() __attribute__((shared_trylock_function));
void stf_function_args() SHARED_TRYLOCK_FUNCTION(1, mu2);
void stf_function_arg() SHARED_TRYLOCK_FUNCTION(1);
int stf_testfn(int y) SHARED_TRYLOCK_FUNCTION(1);
int stf_testfn(int y) {
int x SHARED_TRYLOCK_FUNCTION(1) = y; return x;
};
int stf_test_var SHARED_TRYLOCK_FUNCTION(1);
void stf_fun_params(int lvar SHARED_TRYLOCK_FUNCTION(1));
class StfFoo {
private:
int test_field SHARED_TRYLOCK_FUNCTION(1); void test_method() SHARED_TRYLOCK_FUNCTION(1); };
class SHARED_TRYLOCK_FUNCTION(1) StfTestClass { };
int stf_function_1() SHARED_TRYLOCK_FUNCTION(1, muWrapper.mu);
int stf_function_2() SHARED_TRYLOCK_FUNCTION(1, muDoubleWrapper.muWrapper->mu);
int stf_function_3() SHARED_TRYLOCK_FUNCTION(1, muWrapper.getMu());
int stf_function_4() SHARED_TRYLOCK_FUNCTION(1, *muWrapper.getMuPointer());
int stf_function_5() SHARED_TRYLOCK_FUNCTION(1, &mu1);
int stf_function_6() SHARED_TRYLOCK_FUNCTION(1, muRef);
int stf_function_7() SHARED_TRYLOCK_FUNCTION(1, muDoubleWrapper.getWrapper()->getMu());
int stf_function_8() SHARED_TRYLOCK_FUNCTION(1, muPointer);
int stf_function_9() SHARED_TRYLOCK_FUNCTION(true);
int stf_function_bad_1() SHARED_TRYLOCK_FUNCTION(mu1); int stf_function_bad_2() SHARED_TRYLOCK_FUNCTION("mu"); int stf_function_bad_3() SHARED_TRYLOCK_FUNCTION(muDoublePointer);
int stf_function_bad_4() SHARED_TRYLOCK_FUNCTION(1, "mu"); int stf_function_bad_5() SHARED_TRYLOCK_FUNCTION(1, muDoublePointer); int stf_function_bad_6() SHARED_TRYLOCK_FUNCTION(1, umu);
#if !__has_attribute(unlock_function)
#error "Should support unlock_function attribute"
#endif
void uf_function() UNLOCK_FUNCTION();
void uf_function_args() UNLOCK_FUNCTION(mu1, mu2);
int uf_testfn(int y) UNLOCK_FUNCTION();
int uf_testfn(int y) {
int x UNLOCK_FUNCTION() = y; return x;
};
int uf_test_var UNLOCK_FUNCTION();
class UfFoo {
private:
int test_field UNLOCK_FUNCTION(); void test_method() UNLOCK_FUNCTION(); };
class NO_THREAD_SAFETY_ANALYSIS UfTestClass { };
void uf_fun_params(int lvar UNLOCK_FUNCTION());
int uf_function_1() UNLOCK_FUNCTION(muWrapper.mu);
int uf_function_2() UNLOCK_FUNCTION(muDoubleWrapper.muWrapper->mu);
int uf_function_3() UNLOCK_FUNCTION(muWrapper.getMu());
int uf_function_4() UNLOCK_FUNCTION(*muWrapper.getMuPointer());
int uf_function_5() UNLOCK_FUNCTION(&mu1);
int uf_function_6() UNLOCK_FUNCTION(muRef);
int uf_function_7() UNLOCK_FUNCTION(muDoubleWrapper.getWrapper()->getMu());
int uf_function_8() UNLOCK_FUNCTION(muPointer);
int uf_function_9(Mutex x) UNLOCK_FUNCTION(1);
int uf_function_9(Mutex x, Mutex y) UNLOCK_FUNCTION(1,2);
int uf_function_bad_2() UNLOCK_FUNCTION("mu"); int uf_function_bad_3() UNLOCK_FUNCTION(muDoublePointer); int uf_function_bad_4() UNLOCK_FUNCTION(umu);
int uf_function_bad_1() UNLOCK_FUNCTION(1); int uf_function_bad_5(Mutex x) UNLOCK_FUNCTION(0); int uf_function_bad_6(Mutex x, Mutex y) UNLOCK_FUNCTION(0); int uf_function_bad_7() UNLOCK_FUNCTION(0);
#if !__has_attribute(lock_returned)
#error "Should support lock_returned attribute"
#endif
void lr_function() __attribute__((lock_returned));
void lr_function_arg() LOCK_RETURNED(mu1);
void lr_function_args() __attribute__((lock_returned(mu1, mu2)));
int lr_testfn(int y) LOCK_RETURNED(mu1);
int lr_testfn(int y) {
int x LOCK_RETURNED(mu1) = y; return x;
};
int lr_test_var LOCK_RETURNED(mu1);
void lr_fun_params(int lvar LOCK_RETURNED(mu1));
class LrFoo {
private:
int test_field LOCK_RETURNED(mu1); void test_method() LOCK_RETURNED(mu1);
};
class LOCK_RETURNED(mu1) LrTestClass { };
int lr_function_1() LOCK_RETURNED(muWrapper.mu);
int lr_function_2() LOCK_RETURNED(muDoubleWrapper.muWrapper->mu);
int lr_function_3() LOCK_RETURNED(muWrapper.getMu());
int lr_function_4() LOCK_RETURNED(*muWrapper.getMuPointer());
int lr_function_5() LOCK_RETURNED(&mu1);
int lr_function_6() LOCK_RETURNED(muRef);
int lr_function_7() LOCK_RETURNED(muDoubleWrapper.getWrapper()->getMu());
int lr_function_8() LOCK_RETURNED(muPointer);
int lr_function_bad_1() LOCK_RETURNED(1); int lr_function_bad_2() LOCK_RETURNED("mu"); int lr_function_bad_3() LOCK_RETURNED(muDoublePointer); int lr_function_bad_4() LOCK_RETURNED(umu);
#if !__has_attribute(locks_excluded)
#error "Should support locks_excluded attribute"
#endif
void le_function() __attribute__((locks_excluded));
void le_function_arg() LOCKS_EXCLUDED(mu1);
void le_function_args() LOCKS_EXCLUDED(mu1, mu2);
int le_testfn(int y) LOCKS_EXCLUDED(mu1);
int le_testfn(int y) {
int x LOCKS_EXCLUDED(mu1) = y; return x;
};
int le_test_var LOCKS_EXCLUDED(mu1);
void le_fun_params(int lvar LOCKS_EXCLUDED(mu1));
class LeFoo {
private:
int test_field LOCKS_EXCLUDED(mu1); void test_method() LOCKS_EXCLUDED(mu1);
};
class LOCKS_EXCLUDED(mu1) LeTestClass { };
int le_function_1() LOCKS_EXCLUDED(muWrapper.mu);
int le_function_2() LOCKS_EXCLUDED(muDoubleWrapper.muWrapper->mu);
int le_function_3() LOCKS_EXCLUDED(muWrapper.getMu());
int le_function_4() LOCKS_EXCLUDED(*muWrapper.getMuPointer());
int le_function_5() LOCKS_EXCLUDED(&mu1);
int le_function_6() LOCKS_EXCLUDED(muRef);
int le_function_7() LOCKS_EXCLUDED(muDoubleWrapper.getWrapper()->getMu());
int le_function_8() LOCKS_EXCLUDED(muPointer);
int le_function_bad_1() LOCKS_EXCLUDED(1); int le_function_bad_2() LOCKS_EXCLUDED("mu"); int le_function_bad_3() LOCKS_EXCLUDED(muDoublePointer); int le_function_bad_4() LOCKS_EXCLUDED(umu);
#if !__has_attribute(exclusive_locks_required)
#error "Should support exclusive_locks_required attribute"
#endif
void elr_function() __attribute__((exclusive_locks_required));
void elr_function_arg() EXCLUSIVE_LOCKS_REQUIRED(mu1);
void elr_function_args() EXCLUSIVE_LOCKS_REQUIRED(mu1, mu2);
int elr_testfn(int y) EXCLUSIVE_LOCKS_REQUIRED(mu1);
int elr_testfn(int y) {
int x EXCLUSIVE_LOCKS_REQUIRED(mu1) = y; return x;
};
int elr_test_var EXCLUSIVE_LOCKS_REQUIRED(mu1);
void elr_fun_params(int lvar EXCLUSIVE_LOCKS_REQUIRED(mu1));
class ElrFoo {
private:
int test_field EXCLUSIVE_LOCKS_REQUIRED(mu1); void test_method() EXCLUSIVE_LOCKS_REQUIRED(mu1);
};
class EXCLUSIVE_LOCKS_REQUIRED(mu1) ElrTestClass { };
int elr_function_1() EXCLUSIVE_LOCKS_REQUIRED(muWrapper.mu);
int elr_function_2() EXCLUSIVE_LOCKS_REQUIRED(muDoubleWrapper.muWrapper->mu);
int elr_function_3() EXCLUSIVE_LOCKS_REQUIRED(muWrapper.getMu());
int elr_function_4() EXCLUSIVE_LOCKS_REQUIRED(*muWrapper.getMuPointer());
int elr_function_5() EXCLUSIVE_LOCKS_REQUIRED(&mu1);
int elr_function_6() EXCLUSIVE_LOCKS_REQUIRED(muRef);
int elr_function_7() EXCLUSIVE_LOCKS_REQUIRED(muDoubleWrapper.getWrapper()->getMu());
int elr_function_8() EXCLUSIVE_LOCKS_REQUIRED(muPointer);
int elr_function_bad_1() EXCLUSIVE_LOCKS_REQUIRED(1); int elr_function_bad_2() EXCLUSIVE_LOCKS_REQUIRED("mu"); int elr_function_bad_3() EXCLUSIVE_LOCKS_REQUIRED(muDoublePointer); int elr_function_bad_4() EXCLUSIVE_LOCKS_REQUIRED(umu);
#if !__has_attribute(shared_locks_required)
#error "Should support shared_locks_required attribute"
#endif
void slr_function() __attribute__((shared_locks_required));
void slr_function_arg() SHARED_LOCKS_REQUIRED(mu1);
void slr_function_args() SHARED_LOCKS_REQUIRED(mu1, mu2);
int slr_testfn(int y) SHARED_LOCKS_REQUIRED(mu1);
int slr_testfn(int y) {
int x SHARED_LOCKS_REQUIRED(mu1) = y; return x;
};
int slr_test_var SHARED_LOCKS_REQUIRED(mu1);
void slr_fun_params(int lvar SHARED_LOCKS_REQUIRED(mu1));
class SlrFoo {
private:
int test_field SHARED_LOCKS_REQUIRED(mu1); void test_method() SHARED_LOCKS_REQUIRED(mu1);
};
class SHARED_LOCKS_REQUIRED(mu1) SlrTestClass { };
int slr_function_1() SHARED_LOCKS_REQUIRED(muWrapper.mu);
int slr_function_2() SHARED_LOCKS_REQUIRED(muDoubleWrapper.muWrapper->mu);
int slr_function_3() SHARED_LOCKS_REQUIRED(muWrapper.getMu());
int slr_function_4() SHARED_LOCKS_REQUIRED(*muWrapper.getMuPointer());
int slr_function_5() SHARED_LOCKS_REQUIRED(&mu1);
int slr_function_6() SHARED_LOCKS_REQUIRED(muRef);
int slr_function_7() SHARED_LOCKS_REQUIRED(muDoubleWrapper.getWrapper()->getMu());
int slr_function_8() SHARED_LOCKS_REQUIRED(muPointer);
int slr_function_bad_1() SHARED_LOCKS_REQUIRED(1); int slr_function_bad_2() SHARED_LOCKS_REQUIRED("mu"); int slr_function_bad_3() SHARED_LOCKS_REQUIRED(muDoublePointer); int slr_function_bad_4() SHARED_LOCKS_REQUIRED(umu);
int trivially_false_edges(bool b) {
if (false) return 1;
else return 2;
}
class UnFoo {
public:
void foo();
};
template<void (UnFoo::*methptr)()>
class MCaller {
public:
static void call_method_ptr(UnFoo *f) {
(f->*methptr)();
}
};
void call_method_ptr_inst(UnFoo* f) {
MCaller<&UnFoo::foo>::call_method_ptr(f);
}
int temp;
void empty_back_edge() {
for (;;) {
++temp;
if (temp > 10) break;
}
}
struct Foomger {
void operator++();
};
struct Foomgoper {
Foomger f;
bool done();
void invalid_back_edge() {
do {
++f;
} while (!done());
}
};
template <typename Mutex>
struct SCOPED_LOCKABLE SLTemplateClass {
~SLTemplateClass() UNLOCK_FUNCTION();
};
template <typename Mutex>
struct NonSLTemplateClass {
~NonSLTemplateClass() UNLOCK_FUNCTION(); };
template <>
struct SLTemplateClass<int> {};
template <typename Mutex>
struct SLTemplateDerived : public SLTemplateClass<Mutex> {
~SLTemplateDerived() UNLOCK_FUNCTION();
};
template struct SLTemplateDerived<int>;
struct SLDerived1 : public SLTemplateClass<double> {
~SLDerived1() UNLOCK_FUNCTION();
};
struct SLDerived2 : public SLTemplateClass<int> {
~SLDerived2() UNLOCK_FUNCTION(); };
struct SLDerived3 : public SLTemplateDerived<int> {
~SLDerived3() UNLOCK_FUNCTION(); };
Mutex gmu;
class StaticMu {
static Mutex statmu;
};
class FooLate {
public:
void foo1() EXCLUSIVE_LOCKS_REQUIRED(gmu) { }
void foo2() EXCLUSIVE_LOCKS_REQUIRED(mu) { }
void foo3(Mutex *m) EXCLUSIVE_LOCKS_REQUIRED(m) { }
void foo3(FooLate *f) EXCLUSIVE_LOCKS_REQUIRED(f->mu) { }
void foo4(FooLate *f) EXCLUSIVE_LOCKS_REQUIRED(f->mu);
static void foo5() EXCLUSIVE_LOCKS_REQUIRED(mu);
#if __cplusplus <= 199711L
#endif
template <class T>
void foo6() EXCLUSIVE_LOCKS_REQUIRED(T::statmu) { }
template <class T>
void foo7(T* f) EXCLUSIVE_LOCKS_REQUIRED(f->mu) { }
int a GUARDED_BY(gmu);
int b GUARDED_BY(mu);
int c GUARDED_BY(this->mu);
Mutex mu;
};
class LOCKABLE EmptyArgListsTest {
void lock() EXCLUSIVE_LOCK_FUNCTION() { }
void unlock() UNLOCK_FUNCTION() { }
};
namespace FunctionDefinitionParseTest {
class Foo {
public:
Mutex mu_;
void foo1();
void foo2(Foo *f);
};
template <class T>
class Bar {
public:
Mutex mu_;
void bar();
};
void Foo::foo1() EXCLUSIVE_LOCKS_REQUIRED(mu_) { }
void Foo::foo2(Foo *f) EXCLUSIVE_LOCKS_REQUIRED(f->mu_) { }
template <class T>
void Bar<T>::bar() EXCLUSIVE_LOCKS_REQUIRED(mu_) { }
void baz(Foo *f) EXCLUSIVE_LOCKS_REQUIRED(f->mu_) { }
}
namespace TestMultiDecl {
class Foo {
public:
int GUARDED_BY(mu_) a;
int GUARDED_BY(mu_) b, c;
private:
Mutex mu_;
};
}
namespace NestedClassLateDecl {
class Foo {
class Bar {
int a GUARDED_BY(mu);
int b GUARDED_BY(fooMuStatic);
void bar() EXCLUSIVE_LOCKS_REQUIRED(mu) { a = 0; }
void bar2(Bar* b) EXCLUSIVE_LOCKS_REQUIRED(b->mu) { b->a = 0; }
void bar3(Foo* f) EXCLUSIVE_LOCKS_REQUIRED(f->fooMu) { f->a = 0; }
Mutex mu;
};
int a GUARDED_BY(fooMu);
Mutex fooMu;
static Mutex fooMuStatic;
};
}
namespace PointerToMemberTest {
int testEmptyAttribute GUARDED_BY("");
void testEmptyAttributeFunction() EXCLUSIVE_LOCKS_REQUIRED("");
class Graph {
public:
Mutex mu_;
static Mutex* get_static_mu() LOCK_RETURNED(&Graph::mu_);
};
class Node {
public:
void foo() EXCLUSIVE_LOCKS_REQUIRED(&Graph::mu_);
int a GUARDED_BY(&Graph::mu_);
};
}
namespace SmartPointerTest {
template<class T>
class smart_ptr {
public:
T* operator->() { return ptr_; }
T& operator*() { return ptr_; }
private:
T* ptr_;
};
Mutex gmu;
smart_ptr<int> gdat PT_GUARDED_BY(gmu);
class MyClass {
public:
Mutex mu_;
smart_ptr<Mutex> smu_;
smart_ptr<int> a PT_GUARDED_BY(mu_);
int b GUARDED_BY(smu_);
};
}
namespace InheritanceTest {
class LOCKABLE Base {
public:
void lock() EXCLUSIVE_LOCK_FUNCTION();
void unlock() UNLOCK_FUNCTION();
};
class Base2 { };
class Derived1 : public Base { };
class Derived2 : public Base2, public Derived1 { };
class Derived3 : public Base2 { };
class Foo {
Derived1 mu1_;
Derived2 mu2_;
Derived3 mu3_;
int a GUARDED_BY(mu1_);
int b GUARDED_BY(mu2_);
int c GUARDED_BY(mu3_);
void foo() EXCLUSIVE_LOCKS_REQUIRED(mu1_, mu2_) {
a = 0;
b = 0;
}
};
}
namespace InvalidDeclTest {
class Foo { };
namespace {
void Foo::bar(Mutex* mu) LOCKS_EXCLUDED(mu) { } }
}
namespace StaticScopeTest {
class FooStream;
class Foo {
mutable Mutex mu;
int a GUARDED_BY(mu);
static int si GUARDED_BY(mu);
#if __cplusplus <= 199711L
#endif
static void foo() EXCLUSIVE_LOCKS_REQUIRED(mu);
#if __cplusplus <= 199711L
#endif
friend FooStream& operator<<(FooStream& s, const Foo& f)
EXCLUSIVE_LOCKS_REQUIRED(mu);
#if __cplusplus <= 199711L
#endif
};
}
namespace FunctionAttributesInsideClass_ICE_Test {
class Foo {
public:
void method() {
void foo() EXCLUSIVE_LOCKS_REQUIRED(mu); }
};
}
#ifdef CPP11
namespace CRASH_POST_R301735 {
class SomeClass {
public:
void foo() {
auto l = [this] { auto l = [] () EXCLUSIVE_LOCKS_REQUIRED(mu_) {}; };
}
Mutex mu_;
};
}
#endif