aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2015-06-06 09:22:52 +0200
committerXavier Leroy <xavier.leroy@inria.fr>2015-06-06 09:22:52 +0200
commit9f30d4984863ec655a03996646805202dc2a07c9 (patch)
tree8e8ffec4c78175b074c3b95e91a1d7307d062f48
parent74b6f4fd4f43d3075cc6aba6becfb40aacf2cb9a (diff)
downloadcompcert-kvx-9f30d4984863ec655a03996646805202dc2a07c9.tar.gz
compcert-kvx-9f30d4984863ec655a03996646805202dc2a07c9.zip
Error if, in the same scope, a typedef is redefined as a variable, or a variable is redefined as a typedef.
-rw-r--r--cparser/Elab.ml10
1 files changed, 8 insertions, 2 deletions
diff --git a/cparser/Elab.ml b/cparser/Elab.ml
index fe74a786..bcf90f5e 100644
--- a/cparser/Elab.ml
+++ b/cparser/Elab.ml
@@ -778,7 +778,9 @@ and elab_enum_item env ((s, exp), loc) nextval =
"value of enumerator '%s' is not a compile-time constant" s;
(nextval, Some exp') in
if redef Env.lookup_ident env s then
- error loc "redefinition of enumerator '%s'" s;
+ error loc "redefinition of identifier '%s'" s;
+ if redef Env.lookup_typedef env s then
+ error loc "redefinition of typedef '%s' as different kind of symbol" s;
if not (int_representable v (8 * sizeof_ikind enum_ikind) (is_signed_ikind enum_ikind)) then
warning loc "the value of '%s' is not representable with type %a"
s Cprint.typ (TInt(enum_ikind, []));
@@ -1784,11 +1786,15 @@ let enter_typedefs loc env sto dl =
error loc "initializer in typedef";
if redef Env.lookup_typedef env s then
error loc "redefinition of typedef '%s'" s;
+ if redef Env.lookup_ident env s then
+ error loc "redefinition of identifier '%s' as different kind of symbol" s;
let (id, env') = Env.enter_typedef env s ty in
emit_elab loc (Gtypedef(id, ty));
env') env dl
let enter_or_refine_ident local loc env s sto ty =
+ if redef Env.lookup_typedef env s then
+ error loc "redefinition of typedef '%s' as different kind of symbol" s;
match previous_def Env.lookup_ident env s with
| Some(id, II_ident(old_sto, old_ty))
when sto = Storage_extern || Env.in_current_scope env id ->
@@ -1817,7 +1823,7 @@ let enter_or_refine_ident local loc env s sto ty =
in
(id, new_sto, Env.add_ident env id new_sto new_ty)
| Some(id, II_enum v) when Env.in_current_scope env id ->
- error loc "illegal redefinition of enumerator '%s'" s;
+ error loc "redefinition of enumerator '%s'" s;
(id, sto, Env.add_ident env id sto ty)
| _ ->
let (id, env') = Env.enter_ident env s sto ty in (id, sto, env')