aboutsummaryrefslogtreecommitdiffstats
path: root/cfrontend/C2C.ml
diff options
context:
space:
mode:
authorMichael Schmidt <github@mschmidt.me>2016-10-19 16:08:44 +0200
committerMichael Schmidt <github@mschmidt.me>2016-10-19 16:08:44 +0200
commit8c77560102fbad568209544d30679ca5a3310b37 (patch)
tree2b037168ec72d8ce1ebf1e722c055e6e0fcb40ec /cfrontend/C2C.ml
parentf6ba0da8e008b5bf5fa710eb087e0002e795e29f (diff)
downloadcompcert-8c77560102fbad568209544d30679ca5a3310b37.tar.gz
compcert-8c77560102fbad568209544d30679ca5a3310b37.zip
implement checks for parameters of '__builtin_memcpy_aligned' (bug 20222)
Diffstat (limited to 'cfrontend/C2C.ml')
-rw-r--r--cfrontend/C2C.ml9
1 files changed, 6 insertions, 3 deletions
diff --git a/cfrontend/C2C.ml b/cfrontend/C2C.ml
index 14976d01..85f94ad0 100644
--- a/cfrontend/C2C.ml
+++ b/cfrontend/C2C.ml
@@ -357,12 +357,15 @@ let make_builtin_memcpy args =
let sz1 =
match Initializers.constval !comp_env sz with
| Errors.OK(Vint n) -> n
- | _ -> error "argument 3 of '__builtin_memcpy_aligned' must be a constant"; Integers.Int.zero in
+ | _ -> error "size argument of '__builtin_memcpy_aligned' must be a constant"; Integers.Int.zero in
let al1 =
match Initializers.constval !comp_env al with
| Errors.OK(Vint n) -> n
- | _ -> error "argument 4 of '__builtin_memcpy_aligned' must be a constant"; Integers.Int.one in
- (* to check: sz1 > 0, al1 divides sz1, al1 = 1|2|4|8 *)
+ | _ -> error "alignment argument of '__builtin_memcpy_aligned' must be a constant"; Integers.Int.one in
+ if Integers.Int.is_power2 al1 = None
+ then error "alignment argument of '__builtin_memcpy_aligned' must be a power of 2";
+ if Integers.Int.modu sz1 al1 <> Integers.Int.zero
+ then error "alignment argument of '__builtin_memcpy_aligned' must be a divisor of the size";
(* Issue #28: must decay array types to pointer types *)
Ebuiltin(EF_memcpy(sz1, al1),
Tcons(typeconv(typeof dst),