From 015c64c64a5a547dcef81a75a589eeaf034654cd Mon Sep 17 00:00:00 2001 From: xleroy Date: Sat, 26 Nov 2011 15:27:12 +0000 Subject: Fixed serious bug in handling of volatile arrays. git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1737 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- cfrontend/C2C.ml | 7 +++++-- test/regression/Makefile | 4 ++-- test/regression/Results/volatile1 | 4 ++++ test/regression/volatile1.c | 18 ++++++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 test/regression/Results/volatile1 diff --git a/cfrontend/C2C.ml b/cfrontend/C2C.ml index f35598c7..1287a7ef 100644 --- a/cfrontend/C2C.ml +++ b/cfrontend/C2C.ml @@ -367,6 +367,10 @@ let first_class_value env ty = let is_volatile_access env e = List.mem C.AVolatile (Cutil.attributes_of_type env e.etyp) && Cutil.is_lvalue e + && begin match Cutil.unroll env e.etyp with + | TFun _ | TArray _ -> false + | _ -> true + end let volatile_kind ty = match ty with @@ -377,8 +381,7 @@ let volatile_kind ty = | Tint(I32, _) -> ("int32", Tint(I32, Signed), Mint32) | Tfloat F32 -> ("float32", ty, Mfloat32) | Tfloat F64 -> ("float64", ty, Mfloat64) - | Tpointer _ | Tarray _ | Tfunction _ | Tcomp_ptr _ -> - ("pointer", Tpointer Tvoid, Mint32) + | Tpointer _ -> ("pointer", Tpointer Tvoid, Mint32) | _ -> unsupported "operation on volatile struct or union"; ("", Tvoid, Mint32) diff --git a/test/regression/Makefile b/test/regression/Makefile index aeba3bd3..103901ed 100644 --- a/test/regression/Makefile +++ b/test/regression/Makefile @@ -9,14 +9,14 @@ LIBS=$(LIBMATH) TESTS=attribs1 bitfields1 bitfields2 bitfields3 bitfields4 \ bitfields5 bitfields6 bitfields7 \ - expr1 expr6 initializers volatile2 volatile3 \ + expr1 expr6 initializers volatile1 volatile2 volatile3 \ funct3 expr5 struct7 struct8 struct11 casts1 casts2 char1 \ sizeof1 sizeof2 packedstruct1 # Other tests: should compile to .s without errors (but expect warnings) EXTRAS=annot1 commaprec expr2 expr3 expr4 extern1 funct2 funptr1 init1 \ init2 init3 init4 pragmas ptrs1 ptrs2 struct1 struct2 struct3 \ - struct4 struct5 struct6 struct9 struct10 types1 volatile1 + struct4 struct5 struct6 struct9 struct10 types1 # Test known to fail FAILURES=funct1 varargs1 diff --git a/test/regression/Results/volatile1 b/test/regression/Results/volatile1 new file mode 100644 index 00000000..2be2eb24 --- /dev/null +++ b/test/regression/Results/volatile1 @@ -0,0 +1,4 @@ +f1() = 123 +v = 42 +f3() = 44 +f5(2) = 2 diff --git a/test/regression/volatile1.c b/test/regression/volatile1.c index 850bbeda..10a7abea 100644 --- a/test/regression/volatile1.c +++ b/test/regression/volatile1.c @@ -1,3 +1,5 @@ +#include + volatile int v; int f1(void) { return v; } @@ -7,3 +9,19 @@ void f2(void) { v = 42; } int f3(void) { return v / v + 1 + v; } void f4(void) { v; } + +volatile int t[2]; + +int f5(int x) { t[0] = x; return t[0]; } + +int main() +{ + v = 123; + printf("f1() = %d\n", f1()); + f2(); + printf("v = %d\n", v); + printf("f3() = %d\n", f3()); + f4(); + printf("f5(2) = %d\n", f5(2)); + return 0; +} -- cgit