From 3b8a094dafdeea5499239adadaf24d2b8bdb1f76 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Tue, 30 Dec 2014 17:10:43 +0100 Subject: PR#6: fix handling of wchar_t and assignments from wide string literals. - cparser/Machine indicates whether wchar_t is signed or not (it is signed int in Linux and BSD, but unsigned short in Win32) - The type of a wide string literal is "wchar_t *" if the typedef "wchar_t" exists in the environment (e.g. after #include ). Only if wchar_t is not defined do we use the default from Machine. - Permit initialization of any integer array from a wide string literal, not just an array of wchar_t. --- cparser/Cutil.mli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cparser/Cutil.mli') diff --git a/cparser/Cutil.mli b/cparser/Cutil.mli index 0de0c827..309981be 100644 --- a/cparser/Cutil.mli +++ b/cparser/Cutil.mli @@ -153,7 +153,7 @@ val ptrdiff_t_ikind : ikind (* Helpers for type-checking *) -val type_of_constant : constant -> typ +val type_of_constant : Env.t -> constant -> typ (* Return the type of the given constant. *) val type_of_member : Env.t -> field -> typ (* Return the type of accessing the given field [fld]. -- cgit From 442e3140f4a2172bbc1ee7ce260eb1a8fd79ae95 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Thu, 1 Jan 2015 11:08:12 +0100 Subject: Revised type compatibility check w.r.t. handling of attributes. We now distinguish 3 modes (instead of 2 previously) for attributes: 1- strict compatibility, 2- ignore top-level attrs, 3- ignore all attrs recursively. In strict mode, const/volatile/restrict attributes must be identical, but nonstandard attributes may vary. Also: ignore top-level attrs when comparing function argument types, like GCC/Clang do. Net result is fewer warnings and type-checking that is closer to GCC/Clang. --- cparser/Cutil.mli | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'cparser/Cutil.mli') diff --git a/cparser/Cutil.mli b/cparser/Cutil.mli index 309981be..53bcfcea 100644 --- a/cparser/Cutil.mli +++ b/cparser/Cutil.mli @@ -58,12 +58,28 @@ val attr_inherited_by_members: attribute -> bool (* Is an attribute of a composite inherited by members of the composite? *) (* Type compatibility *) -val compatible_types : ?noattrs: bool -> Env.t -> typ -> typ -> bool + +type attr_handling = + | AttrCompat + | AttrIgnoreTop + | AttrIgnoreAll + +val compatible_types : attr_handling -> Env.t -> typ -> typ -> bool (* Check that the two given types are compatible. - If [noattrs], ignore attributes (recursively). *) -val combine_types : ?noattrs: bool -> Env.t -> typ -> typ -> typ option + The attributes in the types are compared according to the first argument: +- [AttrCompat]: the types must have the same standard attributes + ([const], [volatile], [restrict]) but may differ on custom attributes. +- [AttrIgnoreTop]: the top-level attributes of the two types are ignored, + but attributes of e.g. types of pointed objects (for pointer types) + are compared as per [AttrCompat]. +- [AttrIgnoreAll]: recursively ignore the attributes in the two types. *) +val combine_types : attr_handling -> Env.t -> typ -> typ -> typ option (* Like [compatible_types], but if the two types are compatible, - return the most precise type compatible with both. *) + return the most precise type compatible with both. + The attributes are compared according to the first argument, + with the same meaning as for [compatible_types]. + When two sets of attributes are compatible, the result of + [combine_types] carries the union of these two sets of attributes. *) (* Size and alignment *) -- cgit