Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add more test cases

  • Loading branch information...
commit 4524e6803c489ddfec2a3a986318b91f8726d826 1 parent 10bfdbe
@bblum authored
Showing with 258 additions and 0 deletions.
  1. +72 −0 banana-bowl.c
  2. +63 −0 onion-grill.c
  3. +60 −0 onion-station.c
  4. +63 −0 union.c
View
72 banana-bowl.c
@@ -0,0 +1,72 @@
+#ifdef ATOMIC_ALL_NIGHTERS
+/* function annotations */
+#define MAY_SLEEP __attribute__((atomic_all_nighters("might_sleep")))
+#define WONT_SLEEP __attribute__((atomic_all_nighters("wont_sleep")))
+
+/* context-changing annotations */
+#define ENTER_ATOMIC __attribute__((atomic_all_nighters("wont_sleep","force_enable")))
+#define EXIT_ATOMIC __attribute__((atomic_all_nighters("wont_sleep","force_disable")))
+#define ENTER_ATOMIC_NESTED __attribute__((atomic_all_nighters("wont_sleep","enter_nested")))
+#define EXIT_ATOMIC_NESTED __attribute__((atomic_all_nighters("wont_sleep","exit_nested")))
+
+#else
+#define MAY_SLEEP
+#define WONT_SLEEP
+#define ENTER_ATOMIC
+#define EXIT_ATOMIC
+#define ENTER_ATOMIC_NESTED
+#define EXIT_ATOMIC_NESTED
+#define WONT_SLEEP
+#define MAY_SLEEP
+#endif
+
+struct mutex;
+struct spinlock;
+
+void MAY_SLEEP mutex_lock(struct mutex *mp);
+void MAY_SLEEP mutex_unlock(struct mutex *mp);
+void WONT_SLEEP mutex_assert_is_locked(struct mutex *mp);
+
+void ENTER_ATOMIC_NESTED spin_lock(struct spinlock *sp);
+void EXIT_ATOMIC_NESTED spin_unlock(struct spinlock *sp);
+
+struct spinlock *a;
+struct mutex *m;
+
+int x;
+
+void WONT_SLEEP banana()
+{
+ x++;
+}
+
+void MAY_SLEEP apple()
+{
+ mutex_lock(m);
+ x++;
+ mutex_unlock(m);
+}
+
+struct banana_bowl {
+ void (*f)(void) WONT_SLEEP;
+};
+
+struct fruit_bowl {
+ void (*f)(void) MAY_SLEEP;
+};
+
+int MAY_SLEEP main()
+{
+ // This should fail.
+ // The struct pointer acts as a reference cell, assignment to which
+ // must be neither covariant nor contravariant.
+ struct banana_bowl bananas;
+ struct fruit_bowl *fruit;
+
+ bananas.f = banana;
+ fruit = &bananas;
+ fruit->f = apple;
+ spin_lock(a);
+ bananas.f();
+ spin_unlock(a);
+}
View
63 onion-grill.c
@@ -0,0 +1,63 @@
+#ifdef ATOMIC_ALL_NIGHTERS
+/* function annotations */
+#define MAY_SLEEP __attribute__((atomic_all_nighters("might_sleep")))
+#define WONT_SLEEP __attribute__((atomic_all_nighters("wont_sleep")))
+
+/* context-changing annotations */
+#define ENTER_ATOMIC __attribute__((atomic_all_nighters("wont_sleep","force_enable")))
+#define EXIT_ATOMIC __attribute__((atomic_all_nighters("wont_sleep","force_disable")))
+#define ENTER_ATOMIC_NESTED __attribute__((atomic_all_nighters("wont_sleep","enter_nested")))
+#define EXIT_ATOMIC_NESTED __attribute__((atomic_all_nighters("wont_sleep","exit_nested")))
+
+#else
+#define MAY_SLEEP
+#define WONT_SLEEP
+#define ENTER_ATOMIC
+#define EXIT_ATOMIC
+#define ENTER_ATOMIC_NESTED
+#define EXIT_ATOMIC_NESTED
+#endif
+
+struct mutex;
+struct spinlock;
+
+void mutex_lock(struct mutex *mp) MAY_SLEEP;
+void mutex_unlock(struct mutex *mp) MAY_SLEEP;
+void mutex_assert_is_locked(struct mutex *mp) WONT_SLEEP;
+
+void spin_lock(struct spinlock *sp) ENTER_ATOMIC_NESTED;
+void spin_unlock(struct spinlock *sp) EXIT_ATOMIC_NESTED;
+
+struct spinlock *a;
+struct mutex *m;
+
+/* h2 <: h1 */
+
+void (*h1)(struct mutex *) MAY_SLEEP;
+void (*h2)(struct mutex *) WONT_SLEEP;
+
+/* g1 <: g2 */
+
+void WONT_SLEEP g1(void (*x)(struct mutex *) MAY_SLEEP)
+{
+ h1 = x;
+}
+
+void MAY_SLEEP g2(void (*x)(struct mutex *) WONT_SLEEP)
+{
+ mutex_lock(m);
+ h2 = x;
+ mutex_unlock(m);
+}
+
+
+int MAY_SLEEP main()
+{
+ /* this should fail - have to use union on the return type */
+ void (*f)(void (*)(struct mutex *) WONT_SLEEP) WONT_SLEEP = 0 ? g1 : g2;
+ spin_lock(a);
+ f(mutex_assert_is_locked);
+ spin_unlock(a);
+ h2(m);
+ // return 0;
+}
View
60 onion-station.c
@@ -0,0 +1,60 @@
+#ifdef ATOMIC_ALL_NIGHTERS
+/* function annotations */
+#define MAY_SLEEP __attribute__((atomic_all_nighters("might_sleep")))
+#define WONT_SLEEP __attribute__((atomic_all_nighters("wont_sleep")))
+
+/* context-changing annotations */
+#define ENTER_ATOMIC __attribute__((atomic_all_nighters("wont_sleep","force_enable")))
+#define EXIT_ATOMIC __attribute__((atomic_all_nighters("wont_sleep","force_disable")))
+#define ENTER_ATOMIC_NESTED __attribute__((atomic_all_nighters("wont_sleep","enter_nested")))
+#define EXIT_ATOMIC_NESTED __attribute__((atomic_all_nighters("wont_sleep","exit_nested")))
+
+#else
+#define MAY_SLEEP
+#define WONT_SLEEP
+#define ENTER_ATOMIC
+#define EXIT_ATOMIC
+#define ENTER_ATOMIC_NESTED
+#define EXIT_ATOMIC_NESTED
+#endif
+
+struct mutex;
+struct spinlock;
+
+void mutex_lock(struct mutex *mp) MAY_SLEEP;
+void mutex_unlock(struct mutex *mp) MAY_SLEEP;
+void mutex_assert_is_locked(struct mutex *mp) WONT_SLEEP;
+
+void spin_lock(struct spinlock *sp) ENTER_ATOMIC_NESTED;
+void spin_unlock(struct spinlock *sp) EXIT_ATOMIC_NESTED;
+
+struct spinlock *a;
+struct mutex *m;
+
+/* h2 <: h1 */
+
+void (*h1)(struct mutex *) MAY_SLEEP;
+void (*h2)(struct mutex *) WONT_SLEEP;
+
+/* g1 <: g2 */
+
+void WONT_SLEEP g1(void (*x)(struct mutex *) MAY_SLEEP)
+{
+ h1 = x;
+}
+
+void MAY_SLEEP g2(void (*x)(struct mutex *) WONT_SLEEP)
+{
+ spin_lock(a);
+ x(m);
+ spin_unlock(a);
+}
+
+
+int MAY_SLEEP main()
+{
+ /* this should fail - have to use intersection on the argument type */
+ void (*f)(void (*)(struct mutex *) MAY_SLEEP) MAY_SLEEP = 0 ? g1 : g2;
+ f(mutex_lock);
+ // return 0;
+}
View
63 union.c
@@ -0,0 +1,63 @@
+#ifdef ATOMIC_ALL_NIGHTERS
+/* function annotations */
+#define MAY_SLEEP __attribute__((atomic_all_nighters("might_sleep")))
+#define WONT_SLEEP __attribute__((atomic_all_nighters("wont_sleep")))
+
+/* context-changing annotations */
+#define ENTER_ATOMIC __attribute__((atomic_all_nighters("wont_sleep","force_enable")))
+#define EXIT_ATOMIC __attribute__((atomic_all_nighters("wont_sleep","force_disable")))
+#define ENTER_ATOMIC_NESTED __attribute__((atomic_all_nighters("wont_sleep","enter_nested")))
+#define EXIT_ATOMIC_NESTED __attribute__((atomic_all_nighters("wont_sleep","exit_nested")))
+
+#else
+#define MAY_SLEEP
+#define WONT_SLEEP
+#define ENTER_ATOMIC
+#define EXIT_ATOMIC
+#define ENTER_ATOMIC_NESTED
+#define EXIT_ATOMIC_NESTED
+#endif
+
+struct mutex;
+struct spinlock;
+
+void MAY_SLEEP mutex_lock(struct mutex *mp);
+void MAY_SLEEP mutex_unlock(struct mutex *mp);
+void WONT_SLEEP mutex_assert_is_locked(struct mutex *mp);
+
+void ENTER_ATOMIC_NESTED spin_lock(struct spinlock *sp);
+void EXIT_ATOMIC_NESTED spin_unlock(struct spinlock *sp);
+
+struct spinlock *a;
+struct mutex *m;
+
+/* h2 <: h1 */
+
+void (*h1)(struct mutex *) MAY_SLEEP;
+void (*h2)(struct mutex *) WONT_SLEEP;
+
+/* g1 <: g2 */
+
+void WONT_SLEEP g1(void (*x)(struct mutex *) MAY_SLEEP)
+{
+ h1 = x;
+}
+
+void MAY_SLEEP g2(void (*x)(struct mutex *) WONT_SLEEP)
+{
+ mutex_lock(m);
+ h2 = x;
+ mutex_unlock(m);
+}
+
+
+int MAY_SLEEP main()
+{
+ /* this should succeed */
+ void (*f)(void (*)(struct mutex *) WONT_SLEEP) MAY_SLEEP = 0 ? g1 : g2;
+ f(mutex_assert_is_locked);
+ spin_lock(a);
+ h2(m);
+ spin_unlock(a);
+ // return 0;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.