Skip to content

Commit 6de857e

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 Copilot-Language#257
1 parent 52185a5 commit 6de857e

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
@@ -33,7 +33,7 @@ genfun name expr ty = C.FunDef cty name [] cvars [C.Return $ Just cexpr] where
3333
mkextdecln :: External -> C.Decln
3434
mkextdecln (External name _ ty) = decln where
3535
decln = C.VarDecln (Just C.Extern) cty name Nothing
36-
cty = transtype ty
36+
cty = C.Volatile (transtype ty)
3737

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

0 commit comments

Comments
 (0)