Skip to content

Commit

Permalink
Hack fix the switch-return bug. Think there's a Language.C bug lurking.
Browse files Browse the repository at this point in the history
  • Loading branch information
bblum committed May 2, 2013
1 parent 50cb951 commit a55122f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Check.hs
Expand Up @@ -551,7 +551,6 @@ checkFunDef (CFunDef specs declr oldstyle body nobe) =
[M "entry context" g, M "exit context" gnew]
Nothing -> return ()
-- check all returned contexts against each other
endings <- ends <$> get
case endings of
(gs:rest) ->
do when (not $ all (== gnew) gs) $
Expand Down Expand Up @@ -822,7 +821,8 @@ checkStat (CSwitch e s nobe) =
(_, r) <- checkStat s
gs <- exitSwitch
mergeContexts nobe g0 gs
return (Base, r)
--- XXX: A bit of a hack. Hard to tell when a switch returns.
return (Base, False) -- r)
checkStat (CWhile e s isDoWhile nobe) =
do g0 <- getContext
when (not isDoWhile) $ checkExpr_ e
Expand Down
4 changes: 4 additions & 0 deletions aan-fail-wrap.sh
Expand Up @@ -5,6 +5,10 @@ DIR=~/atomic-all-nighters
RV=0

for i in $@; do
if grep IGNORE $i >/dev/null 2>/dev/null; then
echo -e "\033[01;33m$i:\033[80D\033[64CIgnored\033[00m"
continue
fi
$DIR/bin/aan `cat $DIR/aan-options | tr -d '\n'` $i >/dev/null
RES=$?
if [ "$RES" = 0 ]; then
Expand Down
4 changes: 4 additions & 0 deletions aan-wrap.sh
Expand Up @@ -5,6 +5,10 @@ DIR=~/atomic-all-nighters
RV=0

for i in $@; do
if grep IGNORE $i >/dev/null 2>/dev/null; then
echo -e "\033[01;33m$i:\033[80D\033[64CIgnored\033[00m"
continue
fi
$DIR/bin/aan `cat $DIR/aan-options | tr -d '\n'` $i
RES=$?
if [ "$RES" = 0 ]; then
Expand Down
49 changes: 49 additions & 0 deletions tests/pass/switch-return-ok.c
@@ -0,0 +1,49 @@
#ifdef ATOMIC_ALL_NIGHTERS
/* function annotations */
#define MAY_SLEEP __attribute__((atomic_all_nighters("might_sleep")))

/* context-changing annotations */
#define ENTER_ATOMIC __attribute__((atomic_all_nighters("wont_sleep","force_disable")))
#define EXIT_ATOMIC __attribute__((atomic_all_nighters("wont_sleep","force_enable")))
#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 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 spin_lock(struct spinlock *sp) ENTER_ATOMIC_NESTED;
void spin_unlock(struct spinlock *sp) EXIT_ATOMIC_NESTED;

struct spinlock *a;
struct spinlock *b;
struct mutex *m;

int x;
int y;
int z;

ENTER_ATOMIC void disable_interrupts();
EXIT_ATOMIC void enable_interrupts();

int EXIT_ATOMIC main() {
// This should fail.
// IGNORE: Apparent bug in Language.C? Putting braces around works.
switch (x) {
case 0:
enable_interrupts();
return;
}
enable_interrupts();
return 0;
}

0 comments on commit a55122f

Please sign in to comment.