Skip to content

Commit 0c65be3

Browse files
committed
Add the volatile type qualifier to the global variables
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
1 parent f2fd2b2 commit 0c65be3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

copilot-c99/src/Copilot/Compile/C99/CodeGen.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ genfun name expr ty = C.FunDef cty name [] cvars [C.Return $ Just cexpr] where
3131
mkextdecln :: External -> C.Decln
3232
mkextdecln (External name _ ty) = decln where
3333
decln = C.VarDecln (Just C.Extern) cty name Nothing
34-
cty = transtype ty
34+
cty = C.Volatile (transtype ty)
3535

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

0 commit comments

Comments
 (0)