aboutsummaryrefslogtreecommitdiffstats
path: root/cparser/Elab.ml
Commit message (Collapse)AuthorAgeFilesLines
* Do not pass the env back from for stmt decls. (#42)Bernhard Schommer2017-12-121-7/+7
| | | | | | * Do not pass the env back from for stmt decls. This is the source of issue #211, the environment from the elaboration of the declaration and expressions in the for loop should not be passed back.
* Remove unused code. BUg 22642Bernhard Schommer2017-12-081-1/+0
|
* Store the different inlining cases.Bernhard Schommer2017-12-081-1/+1
| | | | | | | In order to correctly support the noinline attribute we must store whether the function was specified with an inline specifer, had a noinline attribute or nothing. Bug 22642
* Make redefinition of composite a fatal error.Bernhard Schommer2017-05-091-2/+1
| | | | | | | The redefinition of a composite with a different tag type is now a fatal error. This should avoid problems when the composite is used. Bug 21542
* Added check for large arrays.Bernhard Schommer2017-02-211-0/+1
| | | | | | | The check tests whether the size calculation of an array overflows or the array covers half of the available address space and reports an error in this case. Bug 21034
* Added gcc noinline attribute.Bernhard Schommer2017-02-191-0/+1
| | | | The noinline attribute prevents functions from inlining.
* Adopted unused variable and attribtue checkBernhard Schommer2017-02-171-0/+1
| | | | | | | | | The unused variable check now uses two passes. One to collect the used variables and one to report the unused variables. Futhermore attribute checks are extended to composite declaration. Also the check is now performed after elaboration. Bug 19872
* Added a simple check for unused variables.Bernhard Schommer2017-02-171-1/+3
| | | | | | | | | | | | | | | | | The check test whether the identifier is used at all in the function and if not issue a warning. It is not tested whether the usage is reachable at all, so int i; if (0) i; would not generate a warning. This is the same as gcc/clang does. The warning is disabled per default, but is active if -Wall is given. Bug 19872
* Do not optimize away the 'return 0' at end of 'main'Xavier Leroy2017-02-171-7/+5
| | | | | | As a cosmetic optimization enabled by the static analysis in Cflow, we used to not insert a 'return 0' at end of 'main' if the body of 'main' cannot fall through. Since this optimization is cosmetic (the back-end will remove the 'return 0' if unused) and since we don't fully trust this static analysis, revert this optimization and always insert 'return 0'.
* Merge pull request #162 from AbsInt/return-analysis-2Xavier Leroy2017-02-151-6/+18
|\ | | | | | | Improved warnings related to function returns
| * More precise warnings about function returnsXavier Leroy2017-02-071-6/+18
| | | | | | | | | | | | | | | | | | | | | | | | This commit introduces a control-flow static analysis over C abstract syntax (file cparser/Cflow.ml) and uses it to - warn for non-void functions that can return by falling through the body - warn more precisely for _Noreturn functions that can return - introduce the "return 0" in "main" functions less often (cosmetic). For the control-flow analysis, the following conservative approximations are made: - any "goto" label is reachable - all cases of a "switch" statement are reachable as soon as the "switch" is reachable (i.e. the switch expression takes all values needed to reach every case) - the boolean expressions in "if", "while", "do"-"while" and "for" can take true and false values, unless they are compile-time constants.
* | Use Printf.sprintf instead of Format.sprintf when possibleXavier Leroy2017-02-091-4/+4
|/ | | | Minor performance tweak. Printf is more efficient for plain formats involving no boxes.
* Merge branch 'elaboration-of-attributes'Xavier Leroy2017-02-061-24/+46
|\
| * Preliminary support for the "noreturn" attributeXavier Leroy2017-02-061-11/+15
| | | | | | | | | | - Mark the "noreturn" attribute as related to function types, so that it is correctly attached to the nearest enclosing function type. - Add this attribute on functions declared / defined _Noreturn (with the C2011 keyword). The information is not used presently but could be useful later.
| * Refactor the classification of attributesXavier Leroy2017-02-031-5/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Introduce Cutil.class_of_attribute to return the class of the given attribute: one among Attr_type attribute related to types (e.g. "aligned") Attr_struct attribute related to struct/union/enum types (e.g. "packed") Attr_function attribute related to function types (e.g. "noreturn") Attr_name attribute related to variable and function declarations (e.g. "section") Attr_unknown attribute was not declared Cutil.declare_attribute is used to associate a class to a custom attribute. Standard attributes (const, volatile, _Alignas, etc) are Attr_type. cfronted/C2C.ml: declare the few attributes that CompCert honors currently. cparser/GCC.ml: a bigger list of attributes taken from GCC, for reference only.
| * Regression: type attributes and array modifiersXavier Leroy2017-02-011-2/+4
| | | | | | | | | | | | | | Owing to the peculiarities of array types in Cutil.change_attributes_type, type-related attributes of the array element type were duplicated on the array type. E.g. elaborating 'const int a[10][5]' produced "a is an array of 5 const arrays of 10 const ints" instead of "a is an array of 5 arrays of 10 const ints"
| * Revised elaboration of attributesXavier Leroy2017-01-311-13/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The treatment of attributes in the current CompCert is often surprising. For example, attribute(xxx) char * x; is parsed as "x is a pointer to a (char modified by attribute "xxx")", while for most attributes (e.g. section attributes) the expected meaning is "x, modified by attribute "xxx", has type pointer to char". CompCert's current treatment comes from the fact that attributes are processed very much like the standard type modifiers `const` and `volatile`, i.e. const char * x; is really "x is a pointer to a const char", not "x is a const pointer to char". This experiment introduces a distinction between type-related attributes (which include the standard modifiers `const` and `volatile`) and other attributes. The other, non-type-related attributes are "floated up" during elaboration so that they apply to the variable or function being declared or defined. In the examples above, attribute(xxx) char * x; // "attribute(xxx)" applies to "x" const char * x; // "const" applies to "char" This may be a step in the right direction but is not the final story. In particular, the `packed` attribute is special-cased when applied to `struct`, like it was before, and future attributes concerning calling conventions would need to be floated up to function types but not higher than that.
* | Remove all overriding opens in Elab.ml. Bug 19872Bernhard Schommer2017-02-031-2/+2
| |
* | Removed Cabshelper open and avoided shadowing.Bernhard Schommer2017-02-031-7/+6
| | | | | | | | | | | | | | | | The Cabshelper is only used in 4 places, so we don't need a global open. Furhtermore the String.t type is now inlined for Cabs to avoid shadowing problems in Elab.ml Bug 19872
* | Remove unused opens.Bernhard Schommer2017-02-031-32/+28
| | | | | | | | | | | | Format was only used in one place without explicit module prefix. The same holds for Env. Bug 19872
* | Removed no longer working check.Bernhard Schommer2017-02-031-14/+4
| | | | | | | | | | | | Since anonymous struct members are kept in the fieldlist, the fieldlist can never be empty in this case. Bug 19872
* | Avoid overflows and report an error.Bernhard Schommer2017-01-311-7/+7
| | | | | | | | | | | | | | Instead of multiplying the array constant directly with the size of the offset the cautious_mul function is used to detect potential overflows. Bug 20765
* | Normalize offset to size_t kind.Bernhard Schommer2017-01-311-2/+4
| |
* | Remove superfluous check.Bernhard Schommer2017-01-311-7/+4
| | | | | | | | | | | | Gcc and clang do not raise an error for this, also it should work for the last array element which can be without size. Bug 20765
* | New version to support designators.Bernhard Schommer2017-01-241-8/+33
| | | | | | | | | | | | | | | | | | The c standard allows member designators for offsetof. The current implementation works by recursively combining the offset of each of the member designators. For array access the size of the subtypes is multiplied by the index and for members the offset of the member is calculated. Bug 20765
* | Simplified version.Bernhard Schommer2017-01-201-10/+8
| | | | | | | | | | | | | | | | The problem was that sub structs are were not correctly aligned. The new version is much simpler and uses the sizeof_struct to calculate the individual offsets and add them up to get correct offest. Bug 20765
* | Also support union. Bug 20765Bernhard Schommer2017-01-201-3/+4
| |
* | Implement offsetof via builtin.Bernhard Schommer2017-01-201-0/+16
|/ | | | | | | | | | | | The implementation of offsetof as macro in the form ((size_t) &((ty*) NULL)->member) has the problem that it cannot be used everywhere were an integer constant expression is allowed, for example in initiliazers of global variables and there is also no check for the case that member is of bitifield type. The new implementation adds a builtin function for this which is replaced by an integer constant during elaboration. Bug 20765
* Allow multiple nameless bit field fields.Bernhard Schommer2016-12-291-2/+4
|
* Avoid exception catch-allXavier Leroy2016-12-261-1/+1
| | | | "try ...; true with _ -> false" is dangerous if "..." raises unexpected exceptions such as Out_of_memory or Stack_overflow.
* Cosmetic indentation changeXavier Leroy2016-12-261-5/+4
|
* Added code for initializers. Bug 20003Bernhard Schommer2016-12-121-1/+19
|
* Moved naming and changed names of aux functionsBernhard Schommer2016-12-121-16/+20
| | | | | | | | The naming of anonymous structs is performed by an additional step in elab_struct_or_union_info instead of in elab_field_group. Also the aux functions are renamed to access. Bug 20003
* Next try for support of anonymous structs.Bernhard Schommer2016-12-071-25/+54
| | | | | | Instead of using idents the anonymous fileds get names of the for <anon>_c where c is a counter of all anonymous members. Bug 20003
* Warning for C11 _Noreturn feature.Bernhard Schommer2016-11-221-4/+10
| | | | The warning for C11 features is now also triggered for _Noreturn.
* Warning for decls without name in composites.Bernhard Schommer2016-11-221-1/+3
| | | | | | The warning missing declarations is now also triggered for declarations without name in field lists of composite types if the declaration is not an anonymous composite or a bitfield member.
* Keep anonymous members of anonymous structs.Bernhard Schommer2016-09-271-2/+4
| | | | | The anonymous members are kept but using them is still an error. Bug 19907
* Improved error messages for wrong vararg calls.Bernhard Schommer2016-09-231-2/+3
| | | | | | Now "expected at least %d" instead of "expected %d". Also improved error message for __builtin_debug. Bug 19872
* Renamed pedantic to implicit-int.Bernhard Schommer2016-09-221-1/+1
| | | | | | | | The only case where compcert raise a pedantic warning was for implicit int parameters. This is the behavior of clang. However since not all other pedantic warnings are supported the behavior of gcc is adopted. Bug 19872.
* Reverted noisy change.Bernhard Schommer2016-09-221-1/+1
| | | | | | In order to empty declarations it is necessary to distinguish between forward declarations and empty declarations. Bug 19859
* Also warn for empty default declarations. Bug 18004Bernhard Schommer2016-09-211-1/+1
|
* Make unnamed default + correct empty struct warning. Bug 18004Bernhard Schommer2016-09-211-2/+2
|
* Allow empty alignment attribute. Bug 18004Bernhard Schommer2016-09-211-0/+1
|
* Fixed typos and reverted error message. Bug 18004Bernhard Schommer2016-09-051-9/+9
|
* Readded parameter number. Bug 18004Bernhard Schommer2016-09-011-6/+6
|
* Reworded warning. Bug 18004Bernhard Schommer2016-09-011-6/+6
|
* Simplified int to pointer tests.Bernhard Schommer2016-09-011-15/+15
| | | | | | Now the same warning is triggered for both cases, int to ptr and ptr to int. Bug 18004
* Fixed error message for & operator. Bug 18004Bernhard Schommer2016-08-311-1/+1
|
* Added conformance warning.Bernhard Schommer2016-08-311-0/+1
| | | | | | This warning should be triggered if a feature is used that is not part of the code CompCert C language. Bug 18004
* Added back logical operator in error. Bug 18004Bernhard Schommer2016-08-311-1/+1
|