aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Schommer <bernhardschommer@gmail.com>2016-09-23 08:48:48 +0200
committerBernhard Schommer <bernhardschommer@gmail.com>2016-09-23 08:48:48 +0200
commit905012098014efe6ac661ca5fdaa30ba80480296 (patch)
tree175ef31b14aae8ed083920ac42402d1846a476a8
parent8fcdd1d52fcaec72edbe2bb93054f007392065f6 (diff)
downloadcompcert-905012098014efe6ac661ca5fdaa30ba80480296.tar.gz
compcert-905012098014efe6ac661ca5fdaa30ba80480296.zip
Improved error messages for wrong vararg calls.
Now "expected at least %d" instead of "expected %d". Also improved error message for __builtin_debug. Bug 19872
-rw-r--r--cfrontend/C2C.ml9
-rw-r--r--cparser/Elab.ml5
2 files changed, 10 insertions, 4 deletions
diff --git a/cfrontend/C2C.ml b/cfrontend/C2C.ml
index 92abac68..14976d01 100644
--- a/cfrontend/C2C.ml
+++ b/cfrontend/C2C.ml
@@ -755,15 +755,20 @@ let rec convertExpr env e =
unsupported "compound literals"; ezero
| C.ECall({edesc = C.EVar {name = "__builtin_debug"}}, args) ->
+ let len = List.length args in
+ if len < 2 then
+ error "too few arguments to function call, expected at least 2, have 0";
let (kind, args1) =
match args with
| {edesc = C.EConst(CInt(n,_,_))} :: args1 when n <> 0L-> (n, args1)
- | _ -> error "argument 1 of '__builtin_debug' must be a non-zero constant"; (1L, args) in
+ | _::args -> error "argument 1 of '__builtin_debug' must be a non-zero constant"; (1L, args)
+ | [] -> assert false (* catched earlier *) in
let (text, args2) =
match args1 with
| {edesc = C.EConst(CStr(txt))} :: args2 -> (txt, args2)
| {edesc = C.EVar id} :: args2 -> (id.name, args2)
- | _ -> error "argument 2 of '__builtin_debug' must be either a string literal or a variable"; ("", args1) in
+ | _::args2 -> error "argument 2 of '__builtin_debug' must be either a string literal or a variable"; ("", args2)
+ | [] -> assert false (* catched earlier *) in
let targs2 = convertTypArgs env [] args2 in
Ebuiltin(
EF_debug(P.of_int64 kind, intern_string text,
diff --git a/cparser/Elab.ml b/cparser/Elab.ml
index 8d14baf1..713ea04e 100644
--- a/cparser/Elab.ml
+++ b/cparser/Elab.ml
@@ -1940,10 +1940,11 @@ let elab_expr vararg loc env a =
| ([],env), _::_ ->
let found = argno - 1 in
let expected = List.length params + found in
- err "too few arguments to function call, expected %d, have %d" expected found; [],env
+ let vararg = if vararg then "at least " else "" in
+ err "too few arguments to function call, expected %s%d, have %d" vararg expected found; [],env
| (_::_,env), [] ->
if vararg
- then args
+ then args
else
let expected = argno - 1 in
let found = List.length (fst args) + expected in