Skip to content

Commit

Permalink
Add the volatile type qualifier to the global variables
Browse files Browse the repository at this point in the history
representing external streams.

As we expect these variables to be modifed concurrently or via
interrupts, the volatile qualifier is appropriate, and prevents
the compiler from performing code motion that might cause unexpected
behavior.

Ideally, these reads (which occur at the beginning of the step function)
should also be protected by a critical section that masks interrupts or
takes a mutex.

Partially addresses #257
  • Loading branch information
robdockins committed Apr 14, 2022
1 parent f2fd2b2 commit 0c65be3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion copilot-c99/src/Copilot/Compile/C99/CodeGen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ genfun name expr ty = C.FunDef cty name [] cvars [C.Return $ Just cexpr] where
mkextdecln :: External -> C.Decln
mkextdecln (External name _ ty) = decln where
decln = C.VarDecln (Just C.Extern) cty name Nothing
cty = transtype ty
cty = C.Volatile (transtype ty)

-- | Make a declaration for a copy of an external variable.
mkextcpydecln :: External -> C.Decln
Expand Down

0 comments on commit 0c65be3

Please sign in to comment.