Changes in / [f94ca7e:2164637]


Ignore:
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • doc/bibliography/cfa.bib

    rf94ca7e r2164637  
    44244424    keywords    = {Plan 9},
    44254425    contributer = {pabuhr@plg},
    4426     title       = {A New {C} Compiler},
     4426    title       = {A New C Compiler},
    44274427    author      = {Ken Thompson},
    44284428    booktitle   = {Proceedings of the Summer 1990 UKUUG Conference},
    44294429    year        = 1990,
    44304430    pages       = {41--51},
    4431     note        = {\href{http://doc.cat-v.org/bell_labs/new_c_compilers/new_c_compiler.pdf}{http://\-doc.cat-v.org/\-bell\_labs/\-new\_c\_compilers/\-new\_c\_compiler.pdf}},
     4431    url         = {http://doc.cat-v.org/bell_labs/new_c_compilers/new_c_compiler.pdf}
    44324432}
    44334433
  • doc/refrat/Makefile

    rf94ca7e r2164637  
    4444
    4545${basename ${DOCUMENT}}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex \
    46                 ../LaTeXmacros/common.tex ../LaTeXmacros/lstlang.sty ../LaTeXmacros/indexstyle ../bibliography/cfa.bib
     46                ../LaTeXmacros/common.tex ../LaTeXmacros/indexstyle ../bibliography/cfa.bib
    4747        # Conditionally create an empty *.ind (index) file for inclusion until makeindex is run.
    4848        if [ ! -r ${basename $@}.ind ] ; then touch ${basename $@}.ind ; fi
     
    7070        fig2dev -L ps $< > $@
    7171
    72 %.pstex : %.fig
    73         fig2dev -L pstex $< > $@
    74         fig2dev -L pstex_t -p $@ $< > $@_t
    75 
    7672# Local Variables: #
    7773# compile-command: "make" #
  • doc/refrat/refrat.bib

    rf94ca7e r2164637  
    22
    33@manual{ANS:C,
    4     keywords    = {ANSI C},
    5     contributer = {gjditchfield@msg},
    6     title       = {American National Standard for Information Systems --
     4    keywords = {ANSI C},
     5    contributer = {gjditchfield@msg},
     6    title = {American National Standard for Information Systems --
    77          Programming Language -- {C}},
    8     organization= {American National Standards Institute},
    9     address     = {1430 Broadway, New York, New York  10018},
    10     month       = dec, year     = 1989,
    11     note        = {X3.159-1989}
     8    organization = {American National Standards Institute},
     9    address = {1430 Broadway, New York, New York  10018},
     10    month = dec, year = 1989,
     11    note = {X3.159-1989}
    1212}
    1313
    1414@manual{ANS:C11,
    15     keywords    = {ANS:C11},
    16     contributer = {gjditchfield@acm.org},
    17     title       = {American National Standard Information Systems --
     15    keywords = {ANS:C11},
     16    contributer = {gjditchfield@acm.org},
     17    title = {American National Standard Information Systems --
    1818          Programming languages -- {C}},
    19     organization= {American National Standards Institute},
    20     address     = {25 West 43rd Street, New York, New York 10036},
    21     month       = may, year     = 2012,
    22     note        = {INCITS/ISO/IEC 9899-2011[2012]}
     19    organization = {American National Standards Institute},
     20    address = {25 West 43rd Street, New York, New York 10036},
     21    month = may, year = 2012,
     22    note = {INCITS/ISO/IEC 9899-2011[2012]}
    2323}
    2424
    2525@book{c++,
    26     keywords    = {C++, ANSI},
    27     author      = {Margaret A. Ellis and Bjarne Stroustrup},
    28     title       = {The Annotated {C}{\tt ++} Reference Manual},
    29     publisher   = {Addison Wesley},
    30     year        = 1990,
    31     edition     = {first}
     26    keywords = {C++, ANSI},
     27    author = {Margaret A. Ellis and Bjarne Stroustrup},
     28    title = {The Annotated {C}{\tt ++} Reference Manual},
     29    publisher = {Addison Wesley},
     30    year = 1990,
     31    edition = {first}
    3232}
    3333
    3434@Unpublished{Ditchfield96:Overview,
    35     author      = "Glen Ditchfield",
    36     title       = "An Overview of Cforall",
    37     note        = "in preparation",
    38     year        = 1996
     35  author =      "Glen Ditchfield",
     36  title =        "An Overview of Cforall",
     37  note =        "in preparation",
     38  year =        1996
    3939}
    4040
    4141@article{Bak:overload,
    42     keywords    = {compilation},
    43     contributer = {gjditchfield@msg},
    44     author      = {T. P. Baker},
    45     title       = {A One-Pass Algorithm for Overload Resolution in {Ada}},
    46     journal     = toplas,
    47     year        = 1982,
    48     month       = oct, volume   = 4, number     = 4, pages      = {601--614},
    49     abstract    = {
     42    keywords = {compilation},
     43    contributer = {gjditchfield@msg},
     44    author = {T. P. Baker},
     45    title = {A One-Pass Algorithm for Overload Resolution in {Ada}},
     46    journal = toplas,
     47    year = 1982,
     48    month = oct, volume = 4, number = 4, pages = {601--614},
     49    abstract = {
    5050        A simple method is presented for detecting ambiguities and finding
    5151        the correct interpretations of expressions in the programming
     
    5656        approach is demonstrated by a brief formal argument.
    5757    },
    58     comment     = {
     58    comment = {
    5959        See also \cite{D:overload}.
    6060        }
     
    7777
    7878@book{clu,
    79     keywords    = {CLU},
    80     contributer = {gjditchfield@msg},
    81     author      = {Barbara Liskov and Russell Atkinson and Toby Bloom and Eliot
     79    keywords = {CLU},
     80    contributer = {gjditchfield@msg},
     81    author = {Barbara Liskov and Russell Atkinson and Toby Bloom and Eliot
    8282    Moss and J. Craig Schaffert and Robert Scheifler and Alan Snyder},
    83     title       = {CLU Reference Manual},
    84     publisher   = {Springer-Verlag},
    85     year        = 1981,
    86     volume      = 114,
    87     series      = {Lecture Notes in Computer Science}
     83    title = {CLU Reference Manual},
     84    publisher = {Springer-Verlag},
     85    year = 1981,
     86    volume = 114,
     87    series = {Lecture Notes in Computer Science}
    8888}
    8989
    9090@manual{SIMULA87,
    91     keywords    = {Simula standard},
    92     contributer = {gjditchfield@msg},
    93     title       = {Databehandling -- Programspr{\aa}k -- {SIMULA}},
    94     organization        = {Standardiseringskommissionen i Sverige},
    95     note        = {Svensk Standard SS 63 61 14},
    96     year        = 1987,
    97     abstract    = {
     91    keywords = {Simula standard},
     92    contributer = {gjditchfield@msg},
     93    title = {Databehandling -- Programspr{\aa}k -- {SIMULA}},
     94    organization = {Standardiseringskommissionen i Sverige},
     95    note = {Svensk Standard SS 63 61 14},
     96    year = 1987,
     97    abstract = {
    9898        Standard for the programming language SIMULA.  Written in English.
    9999    }
     
    112112
    113113@inproceedings{Thompson90new,
    114     title       = {A New {C} Compiler},
    115     author      = {Ken Thompson},
    116     booktitle   = {Proceedings of the Summer 1990 UKUUG Conference},
    117     year        = 1990,
    118     pages       = {41--51}
     114  title = {A New C Compiler},
     115  author = {Ken Thompson},
     116  booktitle = {Proceedings of the Summer 1990 UKUUG Conference},
     117  year = 1990,
     118  pages = {41--51}
    119119}
  • doc/refrat/refrat.tex

    rf94ca7e r2164637  
    1111%% Created On       : Wed Apr  6 14:52:25 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Fri Jun  2 10:43:14 2017
    14 %% Update Count     : 83
     13%% Last Modified On : Wed Apr  5 23:23:28 2017
     14%% Update Count     : 79
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    2929\usepackage{epic,eepic}
    3030\usepackage{upquote}                                                                    % switch curled `'" to straight
    31 \usepackage{calc}
    3231\usepackage{xspace}
    3332\usepackage{varioref}                                                                   % extended references
     
    6362% Names used in the document.
    6463\newcommand{\Version}{\input{../../version}}
     64
    6565\newcommand{\Textbf}[2][red]{{\color{#1}{\textbf{#2}}}}
    6666\newcommand{\Emph}[2][red]{{\color{#1}\textbf{\emph{#2}}}}
     
    9797\renewcommand{\chaptermark}[1]{\markboth{\thechapter\quad #1}{\thechapter\quad #1}}
    9898\renewcommand{\sectionmark}[1]{\markboth{\thesection\quad #1}{\thesection\quad #1}}
    99 \renewcommand{\subsectionmark}[1]{\markboth{\thesubsection\quad #1}{\thesubsection\quad #1}}
    10099\pagenumbering{roman}
    101100\linenumbers                                            % comment out to turn off line numbering
     
    122121
    123122This document is a reference manual and rationale for \CFA, a polymorphic extension of the C programming language.
    124 It covers low-level syntactic and semantic details of the language to address complex language issues for programmers, and provide language implementers with a precise language description.
    125 It makes frequent reference to the \Celeven standard~\cite{C11}, and occasionally compares \CFA to \CC~\cite{C++}.
    126 Changes to the syntax and additional features are expected to be included in later revisions.
    127 
    128 The manual deliberately imitates the ordering of the \Celeven standard (although the section numbering differs).
    129 Unfortunately, this means the manual contains more ``forward references'' than usual, making it harder to follow if the reader does not have a copy of the \Celeven standard.
     123It makes frequent reference to the {\c11} standard \cite{C11}, and occasionally compares \CFA to {\CC} \cite{C++}.
     124
     125The manual deliberately imitates the ordering of the {\c11} standard (although the section numbering differs).
     126Unfortunately, this means the manual contains more ``forward references'' than usual, making it harder to follow if the reader does not have a copy of the {\c11} standard.
    130127For a simple introduction to \CFA, see the companion document ``An Overview of \CFA''
    131128\cite{Ditchfield96:Overview}.
     
    142139\chapter{Terms, definitions, and symbols}
    143140
    144 Terms from the \Celeven standard used in this document have the same meaning as in the \Celeven standard.
     141Terms from the {\c11} standard used in this document have the same meaning as in the {\c11} standard.
    145142
    146143% No ``Conformance'' or ``Environment'' chapters yet.
     
    152149
    153150\section{Notation}
    154 The syntax notation used in this document is the same as in the \Celeven standard, with one exception: ellipsis in the definition of a nonterminal, as in ``\emph{declaration:} \ldots'', indicates that these rules extend a previous definition, which occurs in this document or in the \Celeven standard.
     151The syntax notation used in this document is the same as in the {\c11} standard, with one exception: ellipsis in the definition of a nonterminal, as in ``\emph{declaration:} \ldots'', indicates that these rules extend a previous definition, which occurs in this document or in the {\c11} standard.
    155152
    156153
     
    165162\begin{rationale}
    166163Hence, a \CFA program can declare an ©int v© and a ©float v© in the same scope;
    167 a \CC program can not.
     164a {\CC} program can not.
    168165\end{rationale}
    169166
     
    288285
    289286\begin{rationale}
    290 Note that \Celeven does not include conversion from \Index{real type}s to \Index{complex type}s in the usual arithmetic conversions, and \CFA does not include them as safe conversions.
     287Note that {\c11} does not include conversion from \Index{real type}s to \Index{complex type}s in the usual arithmetic conversions, and \CFA does not include them as safe conversions.
    291288\end{rationale}
    292289
     
    373370\begin{rationale}
    374371As in C, there is an implicit conversion from ©void *© to any pointer type.
    375 This is clearly dangerous, and \CC does not have this implicit conversion.
     372This is clearly dangerous, and {\CC} does not have this implicit conversion.
    376373\CFA\index{deficiencies!void * conversion} keeps it, in the interest of remaining as pure a superset of C as possible, but discourages it by making it unsafe.
    377374\end{rationale}
     
    611608
    612609There are two notable differences between \CFA's overload resolution rules and the rules for
    613 \CC defined in \cite{C++}.
     610{\CC} defined in \cite{C++}.
    614611First, the result type of a function plays a role.
    615 In \CC, a function call must be completely resolved based on the arguments to the call in most circumstances.
     612In {\CC}, a function call must be completely resolved based on the arguments to the call in most circumstances.
    616613In \CFA, a function call may have several interpretations, each with a different result type, and the interpretations of the containing context choose among them.
    617614Second, safe conversions are used to choose among interpretations of all sorts of functions;
    618 in \CC, the ``usual arithmetic conversions'' are a separate set of rules that apply only to the built-in operators.
     615in {\CC}, the ``usual arithmetic conversions'' are a separate set of rules that apply only to the built-in operators.
    619616\end{rationale}
    620617
     
    640637
    641638\begin{rationale}
    642 Expression syntax is quoted from the \Celeven standard.
     639Expression syntax is quoted from the {\c11} standard.
    643640The syntax itself defines the precedence and associativity of operators.
    644641The sections are arranged in decreasing order of precedence, with all operators in a section having the same precedence.
     
    668665The \Index{valid interpretation} of an \nonterm{identifier} are given by the visible\index{visible} declarations of the identifier.
    669666
    670 A \nonterm{constant} or \nonterm{string-literal} has one valid interpretation, which has the type and value defined by \Celeven.
     667A \nonterm{constant} or \nonterm{string-literal} has one valid interpretation, which has the type and value defined by {\c11}.
    671668The predefined integer identifiers ``©1©'' and ``©0©'' have the integer values 1 and 0, respectively.
    672669The other two predefined ``©0©'' identifiers are bound to polymorphic pointer values that, when specialized\index{specialization} with a data type or function type respectively, produce a null pointer of that type.
     
    11161113forall( otype T ) T restrict * ?++( T restrict *restrict volatile * );
    11171114\end{lstlisting} with ©T© inferred to be ©float *©.
    1118 This looks odd, because \Celeven contains a constraint that requires restrict-qualified types to be pointer-to-object types, and ©T© is not syntactically a pointer type. \CFA loosens the constraint.
     1115This looks odd, because {\c11} contains a constraint that requires restrict-qualified types to be pointer-to-object types, and ©T© is not syntactically a pointer type. \CFA loosens the constraint.
    11191116\end{enumerate}
    11201117\end{rationale}
     
    14801477
    14811478\begin{rationale}
    1482 \Celeven does not include conversions from the \Index{real type}s to \Index{complex type}s in the \Index{usual arithmetic conversion}s.  Instead it specifies conversion of the result of binary operations on arguments from mixed type domains. \CFA's predefined operators match that pattern.
     1479{\c11} does not include conversions from the \Index{real type}s to \Index{complex type}s in the \Index{usual arithmetic conversion}s.  Instead it specifies conversion of the result of binary operations on arguments from mixed type domains. \CFA's predefined operators match that pattern.
    14831480\end{rationale}
    14841481
     
    15091506
    15101507\begin{rationale}
    1511 \Celeven defines most arithmetic operations to apply an \Index{integer promotion} to any argument that belongs to a type that has an \Index{integer conversion rank} less than that of ©int©.
     1508{\c11} defines most arithmetic operations to apply an \Index{integer promotion} to any argument that belongs to a type that has an \Index{integer conversion rank} less than that of ©int©.
    15121509If ©s© is a ©short int©, ``©s *s©'' does not have type ©short int©;
    15131510it is treated as ``©( (int)s ) * ( (int)s )©'', and has type ©int©. \CFA matches that pattern;
     
    15221519\end{lstlisting}
    15231520Since \CFA does not define a multiplication operator for ©short int©, ©square( s )© is treated as ©square( (int)s )©, and the result has type ©int©.
    1524 This is mildly surprising, but it follows the \Celeven operator pattern.
     1521This is mildly surprising, but it follows the {\c11} operator pattern.
    15251522
    15261523A more troubling example is
     
    16201617©ptrdiff_t© is an implementation-defined identifier defined in ©<stddef.h>© that is synonymous with a signed integral type that is large enough to hold the difference between two pointers.
    16211618It seems reasonable to use it for pointer addition as well. (This is technically a difference between \CFA and C, which only specifies that pointer addition uses an \emph{integral} argument.) Hence it is also used for subscripting, which is defined in terms of pointer addition.
    1622 The \Celeven standard uses ©size_t© in several cases where a library function takes an argument that is used as a subscript, but ©size_t© is unsuitable here because it is an unsigned type.
     1619The {\c11} standard uses ©size_t© in several cases where a library function takes an argument that is used as a subscript, but ©size_t© is unsuitable here because it is an unsigned type.
    16231620\end{rationale}
    16241621
     
    19331930\end{lstlisting}
    19341931The logical expression calls the ©Rational© inequality operator, passing it ©*rp© and the ©Rational 0©, and getting a 1 or 0 as a result.
    1935 In contrast, \CC would apply a programmer-defined ©Rational©-to-©int© conversion to ©*rp© in the equivalent situation.
     1932In contrast, {\CC} would apply a programmer-defined ©Rational©-to-©int© conversion to ©*rp© in the equivalent situation.
    19361933The conversion to ©int© would produce a general integer value, which is unfortunate, and possibly dangerous if the conversion was not written with this situation in mind.
    19371934\end{rationale}
     
    26292626\begin{itemize}
    26302627\item a typedef name may be redefined to denote the same type as it currently does, provided that type is not a variably modified type;
    2631 \item tags may be redeclared as specified in section 6.7.2.3 of the \Celeven standard.
     2628\item tags may be redeclared as specified in section 6.7.2.3 of the {\c11} standard.
    26322629\end{itemize}
    26332630\begin{rationale}
    2634 This constraint adds the phrase ``with compatible types'' to the \Celeven constraint, to allow overloading.
     2631This constraint adds the phrase ``with compatible types'' to the {\c11} constraint, to allow overloading.
    26352632\end{rationale}
    26362633
    26372634An identifier declared by a type declaration shall not be redeclared as a parameter in a function definition whose declarator includes an identifier list.
    26382635\begin{rationale}
    2639 This restriction echos \Celeven's ban on the redeclaration of typedef names as parameters.
     2636This restriction echos {\c11}'s ban on the redeclaration of typedef names as parameters.
    26402637This avoids an ambiguity between old-style function declarations and new-style function prototypes:
    26412638\begin{lstlisting}
     
    26642661
    26652662\semantics
    2666 \CFA extends the \Celeven definition of \define{anonymous structure} to include structure specifiers with tags, and extends the \Celeven definition of \define{anonymous union} to include union specifiers with tags.
     2663\CFA extends the {\c11} definition of \define{anonymous structure} to include structure specifiers with tags, and extends the {\c11} definition of \define{anonymous union} to include union specifiers with tags.
    26672664\begin{rationale}
    26682665This extension imitates an extension in the Plan 9 C compiler \cite{Thompson90new}.
     
    28572854
    28582855\begin{rationale}
    2859 ©lvalue© provides some of the functionality of \CC's ``©T&©'' ( reference to object of type ©T©) type.
    2860 Reference types have four uses in \CC.
     2856©lvalue© provides some of the functionality of {\CC}'s ``©T&©'' ( reference to object of type ©T©) type.
     2857Reference types have four uses in {\CC}.
    28612858\begin{itemize}
    28622859\item
     
    28652862\item
    28662863A reference can be used to define an alias for a complicated lvalue expression, as a way of getting some of the functionality of the Pascal ©with© statement.
    2867 The following \CC code gives an example.
     2864The following {\CC} code gives an example.
    28682865\begin{lstlisting}
    28692866{
     
    28772874A reference parameter can be used to allow a function to modify an argument without forcing the caller to pass the address of the argument.
    28782875This is most useful for user-defined assignment operators.
    2879 In \CC, plain assignment is done by a function called ``©operator=©'', and the two expressions
     2876In {\CC}, plain assignment is done by a function called ``©operator=©'', and the two expressions
    28802877\begin{lstlisting}
    28812878a = b;
     
    28902887\item
    28912888References to \Index{const-qualified} types can be used instead of value parameters.  Given the
    2892 \CC function call ``©fiddle( a_thing )©'', where the type of ©a_thing© is
     2889{\CC} function call ``©fiddle( a_thing )©'', where the type of ©a_thing© is
    28932890©Thing©, the type of ©fiddle© could be either of
    28942891\begin{lstlisting}
     
    32193216The Simula class \cite{SIMULA87} is essentially a record type.
    32203217Since the only operations on a record are member selection and assignment, which can not be overloaded, there is never any ambiguity as to whether the abstraction or the implementation view is being used.
    3221 In \CC
     3218In {\CC}
    32223219\cite{C++}, operations on class instances include assignment and ``©&©'', which can be overloaded.
    32233220A ``scope resolution'' operator can be used inside the class to specify whether the abstract or implementation version of the operation should be used.
     
    35513548\subsection{Predefined macro names}
    35523549
    3553 The implementation shall define the macro names ©__LINE__©, ©__FILE__©, ©__DATE__©, and ©__TIME__©, as in the \Celeven standard.
     3550The implementation shall define the macro names ©__LINE__©, ©__FILE__©, ©__DATE__©, and ©__TIME__©, as in the {\c11} standard.
    35543551It shall not define the macro name ©__STDC__©.
    35553552
     
    36373634\subsection{Pointer and array types}
    36383635
    3639 Array types can barely be said to exist in \Celeven, since in most cases an array name is treated as a constant pointer to the first element of the array, and the subscript expression ``©a[i]©'' is equivalent to the dereferencing expression ``©(*( a+( i )))©''.
     3636Array types can barely be said to exist in {\c11}, since in most cases an array name is treated as a constant pointer to the first element of the array, and the subscript expression ``©a[i]©'' is equivalent to the dereferencing expression ``©(*( a+( i )))©''.
    36403637Technically, pointer arithmetic and pointer comparisons other than ``©==©'' and ``©!=©'' are only defined for pointers to array elements, but the type system does not enforce those restrictions.
    36413638Consequently, there is no need for a separate ``array type'' specification.
     
    37153712Different operators often have related meanings;
    37163713for instance, in C, ``©+©'', ``©+=©'', and the two versions of ``©++©'' perform variations of addition.
    3717 Languages like \CC and Ada allow programmers to define operators for new types, but do not require that these relationships be preserved, or even that all of the operators be implemented.
     3714Languages like {\CC} and Ada allow programmers to define operators for new types, but do not require that these relationships be preserved, or even that all of the operators be implemented.
    37183715Completeness and consistency is left to the good taste and discretion of the programmer.
    37193716It is possible to encourage these attributes by providing generic operator functions, or member functions of abstract classes, that are defined in terms of other, related operators.
     
    38263823\end{theindex}
    38273824
    3828 
    38293825\end{document}
    38303826
  • doc/user/user.tex

    rf94ca7e r2164637  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Fri Jun  2 10:07:51 2017
    14 %% Update Count     : 2128
     13%% Last Modified On : Tue May 30 11:45:46 2017
     14%% Update Count     : 2098
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    185185While the \CFA I/O looks similar to the \Index*[C++]{\CC{}} output style, there are important differences, such as automatic spacing between variables as in \Index*{Python} (see~\VRef{s:IOLibrary}).
    186186
    187 This document is a programmer reference-manual for the \CFA programming language.
    188 The manual covers the core features of the language and runtime-system, with simple examples illustrating syntax and semantics of each feature.
    189 The manual does not teach programming, i.e., how to combine the new constructs to build complex programs.
    190 A reader should already have an intermediate knowledge of control flow, data structures, and concurrency issues to understand the ideas presented as well as some experience programming in C/\CC.
     187This document is a user manual for the \CFA programming language, targeted at \CFA programmers.
    191188Implementers may refer to the \CFA Programming Language Specification for details about the language syntax and semantics.
     189In its current state, this document covers the intended core features of the language.
    192190Changes to the syntax and additional features are expected to be included in later revisions.
    193191
     
    52445242\begin{description}
    52455243\item[fill]
    5246 after allocation the storage is filled with a specified character.
     5244after allocation the storage is or is not filled with a specified character.
    52475245\item[resize]
    52485246an existing allocation is decreased or increased in size.
    52495247In either case, new storage may or may not be allocated and, if there is a new allocation, as much data from the existing allocation is copied.
    5250 For an increase in storage size, new storage after the copied data may be filled.
     5248For an increase in storage size, new storage after the copied data may or may not be filled.
    52515249\item[alignment]
    52525250an allocation starts on a specified memory boundary, e.g., an address multiple of 64 or 128 for cache-line purposes.
    52535251\item[array]
    52545252the allocation size is scaled to the specified number of array elements.
    5255 An array may be filled, resized, or aligned.
     5253An array may or not be filled, resized, or aligned.
    52565254\end{description}
    5257 The table shows allocation routines supporting different combinations of storage-management capabilities:
     5255
     5256The following table show the allocation routines supporting different combinations of storage-management capabilities:
    52585257\begin{center}
    5259 \begin{tabular}{@{}lr|l|l|l|l@{}}
    5260                 &                                       & \multicolumn{1}{c|}{fill}     & resize        & alignment     & array \\
     5258\begin{tabular}{@{}r|l|l|l|l@{}}
     5259                                        & fill                          & resize        & alignment     & array \\
    52615260\hline
    5262 C               & ©malloc©                      & no                    & no            & no            & no    \\
    5263                 & ©calloc©                      & yes (0 only)  & no            & no            & yes   \\
    5264                 & ©realloc©                     & no/copy               & yes           & no            & no    \\
    5265                 & ©memalign©            & no                    & no            & yes           & no    \\
    5266                 & ©posix_memalign©      & no                    & no            & yes           & no    \\
    5267 C11             & ©aligned_alloc©       & no                    & no            & yes           & no    \\
    5268 \CFA    & ©alloc©                       & no/copy/yes   & no/yes        & no            & yes   \\
    5269                 & ©align_alloc©         & no/yes                & no            & yes           & yes   \\
     5261©malloc©                        & no/yes                        & no/yes        & no            & no    \\
     5262©amalloc©                       & no/copy data/yes      & no/yes        & no            & yes   \\
     5263©calloc©                        & yes (0 only)          & no            & no            & yes   \\
     5264©realloc©                       & no/copy data          & yes           & no            & no    \\
     5265©memalign©                      & no/yes                        & no            & yes           & no    \\
     5266©amemalign©                     & no/yes                        & no            & yes           & yes   \\
     5267©align_alloc©           & no                            & no            & yes           & no    \\
     5268©posix_memalign©        & no                            & no            & yes           & no    \\
    52705269\end{tabular}
    52715270\end{center}
     5271% When ©amalloc© resizes and fills, the space after the copied data from the source is set to the fill character.
    52725272It is impossible to resize with alignment because the underlying ©realloc© allocates storage if more space is needed, and it does not honour alignment from the original allocation.
    52735273
    52745274\leavevmode
    52755275\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    5276 // C unsafe allocation
    5277 extern "C" {
    5278 void * mallac( size_t size );§\indexc{memset}§
    5279 void * calloc( size_t dim, size_t size );§\indexc{calloc}§
    5280 void * realloc( void * ptr, size_t size );§\indexc{realloc}§
    5281 void * memalign( size_t align, size_t size );§\indexc{memalign}§
    5282 int posix_memalign( void ** ptr, size_t align, size_t size );§\indexc{posix_memalign}§
    5283 }
    5284 
    5285 // §\CFA§ safe equivalents, i.e., implicit size specification
    5286 forall( dtype T | sized(T) ) T * malloc( void );
    5287 forall( dtype T | sized(T) ) T * calloc( size_t dim );
    5288 forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size );
    5289 forall( dtype T | sized(T) ) T * memalign( size_t align );
    5290 forall( dtype T | sized(T) ) T * aligned_alloc( size_t align );
    5291 forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t align );
    5292 
    5293 // §\CFA§ safe general allocation, fill, resize, array
    5294 forall( dtype T | sized(T) ) T * alloc( void );§\indexc{alloc}§
    5295 forall( dtype T | sized(T) ) T * alloc( char fill );
    5296 forall( dtype T | sized(T) ) T * alloc( size_t dim );
    5297 forall( dtype T | sized(T) ) T * alloc( size_t dim, char fill );
    5298 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim );
    5299 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill );
    5300 
    5301 // §\CFA§ safe general allocation, align, fill, array
    5302 forall( dtype T | sized(T) ) T * align_alloc( size_t align );
    5303 forall( dtype T | sized(T) ) T * align_alloc( size_t align, char fill );
    5304 forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim );
    5305 forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim, char fill );
    5306 
    5307 // C unsafe initialization/copy
    5308 extern "C" {
    5309 void * memset( void * dest, int c, size_t size );
    5310 void * memcpy( void * dest, const void * src, size_t size );
    5311 }
    5312 
    5313 // §\CFA§ safe initialization/copy
     5276// allocation, non-array types
     5277forall( dtype T | sized(T) ) T * malloc( void );§\indexc{malloc}§
     5278forall( dtype T | sized(T) ) T * malloc( char fill );
     5279
     5280// allocation, array types
     5281forall( dtype T | sized(T) ) T * calloc( size_t dim );§\indexc{cmalloc}§
     5282forall( dtype T | sized(T) ) T * amalloc( size_t dim );§\indexc{amalloc}§  // alternate name for calloc
     5283forall( dtype T | sized(T) ) T * amalloc( size_t dim, char fill );
     5284
     5285// resize, non-array types
     5286forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size );§\indexc{realloc}§
     5287forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size, char fill );
     5288forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size );  // alternate name for realloc
     5289forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size, char fill );
     5290
     5291// resize, array types
     5292forall( dtype T | sized(T) ) T * amalloc( T * ptr, size_t dim );
     5293forall( dtype T | sized(T) ) T * amalloc( T * ptr, size_t dim, char fill );
     5294
     5295// alignment, non-array types
     5296forall( dtype T | sized(T) ) T * memalign( size_t alignment );§\indexc{memalign}§
     5297forall( dtype T | sized(T) ) T * memalign( size_t alignment, char fill );
     5298forall( dtype T | sized(T) ) T * aligned_alloc( size_t alignment );§\indexc{aligned_alloc}§
     5299forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t alignment );§\indexc{posix_memalign}§
     5300
     5301// alignment, array types
     5302forall( dtype T | sized(T) ) T * amemalign( size_t alignment, size_t dim );§\indexc{amemalign}§
     5303forall( dtype T | sized(T) ) T * amemalign( size_t alignment, size_t dim, char fill );
     5304
     5305// data, non-array types
    53145306forall( dtype T | sized(T) ) T * memset( T * dest, char c );§\indexc{memset}§
    53155307forall( dtype T | sized(T) ) T * memcpy( T * dest, const T * src );§\indexc{memcpy}§
    53165308
    5317 // §\CFA§ safe initialization/copy array
    5318 forall( dtype T | sized(T) ) T * memset( T dest[], size_t dim, char c );
    5319 forall( dtype T | sized(T) ) T * memcpy( T dest[], const T src[], size_t dim );
    5320 
    5321 // §\CFA§ allocation/deallocation and constructor/destructor
    5322 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * new( Params p );§\indexc{new}§
     5309// data, array types
     5310forall( dtype T | sized(T) ) T * amemset( T * dest, size_t dim, char c );§\indexc{amemset}§
     5311forall( dtype T | sized(T) ) T * amemcpy( T * dest, const T * src, size_t dim );§\indexc{amemcpy}§
     5312
     5313// allocation/deallocation and constructor/destructor
     5314forall( dtype T, ttype Params | sized(T) | { void ?{}(T *, Params); } ) T * new( Params p );§\indexc{new}§
    53235315forall( dtype T | { void ^?{}( T * ); } ) void delete( T * ptr );§\indexc{delete}§
    5324 forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } )
    5325   void delete( T * ptr, Params rest );
    5326 
    5327 // §\CFA§ allocation/deallocation and constructor/destructor, array
    5328 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * anew( size_t dim, Params p );§\indexc{anew}§
    5329 forall( dtype T | sized(T) | { void ^?{}( T * ); } ) void adelete( size_t dim, T arr[] );§\indexc{adelete}§
    5330 forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } )
    5331   void adelete( size_t dim, T arr[], Params rest );
     5316forall( dtype T, ttype Params | { void ^?{}( T * ); void delete(Params); } ) void delete( T * ptr, Params rest );
    53325317\end{cfa}
    53335318
  • doc/working/exception/impl/except.c

    rf94ca7e r2164637  
    44
    55#include "lsda.h"
    6 
    7 // This macro should be the only thing that needs to change across machines.
    8 // struct _Unwind_Context * -> _Unwind_Reason_Code(*)()
    9 #define MATCHER_FROM_CONTEXT(ptr_to_context) \
    10         (*(_Unwind_Reason_Code(**)())(_Unwind_GetCFA(ptr_to_context) + 8))
    11 
    126
    137//Global which defines the current exception
     
    2317                     struct _Unwind_Exception* unwind_exception, struct _Unwind_Context* context)
    2418{
    25         printf("CFA: 0x%lx\n", _Unwind_GetCFA(context));
    26 
    2719        //DEBUG
    2820        printf("Personality function (%d, %x, %llu, %p, %p):", version, actions, exceptionClass, unwind_exception, context);
     
    119111
    120112                                        //Get a function pointer from the relative offset and call it
    121                                         // _Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher;                                   
    122 
    123                                         _Unwind_Reason_Code (*matcher)() =
    124                                                 MATCHER_FROM_CONTEXT(context);
     113                                        _Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher;                                     
    125114                                        _Unwind_Reason_Code ret = matcher();
    126115
  • doc/working/exception/impl/main.c

    rf94ca7e r2164637  
    11#include <stdio.h>
    22#include "except.h"
    3 
    4 // Requires -fexceptions to work.
    53
    64#define EXCEPTION 2
     
    2826extern int this_exception;
    2927_Unwind_Reason_Code foo_try_match() {
    30         printf(" (foo_try_match called)");
    31         return this_exception == EXCEPTION ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
     28        return this_exception == 3 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
    3229}
    3330
     
    3734//for details
    3835__attribute__((noinline))
    39 void try( void (*try_block)(), void (*catch_block)(),
    40           _Unwind_Reason_Code (*match_block)() )
     36void try( void (*try_block)(), void (*catch_block)() )
    4137{
    42         volatile int xy = 0;
    43         printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy);
    44 
    4538        //Setup statments
    4639        //These 2 statments won't actually result in any code,
     
    10295        "       .uleb128 .CATCH-try\n"                          //Hanlder landing pad adress  (relative to start of function)
    10396        "       .uleb128 1\n"                                           //Action code, gcc seems to use always 0
     97        //Beyond this point we don't match gcc data'
     98        "       .uleb128 foo_try_match-try\n"                   //Handler routine to check if the exception is matched
    10499        ".LLSDACSECFA2:\n"                                              //BODY end
    105100        "       .text\n"                                                        //TABLE footer
     
    127122
    128123        //Actual call to the try block
    129         try( foo_try_block, foo_catch_block, foo_try_match );
     124        try( foo_try_block, foo_catch_block );
    130125
    131126        printf( "Foo exited normally\n" );
    132127}
    133128
    134 // Not in main.cfa
    135 void fy() {
    136         // Currently not destroyed if the exception is caught in fee.
    137         raii_t a = { "Fy dtor" };
    138 
    139         void fy_try_block() {
    140                 raii_t b = { "Fy try dtor" };
    141 
    142                 throw( 3 );
    143         }
    144 
    145         void fy_catch_block() {
    146                 printf("Fy caught exception\n");
    147         }
    148 
    149         _Unwind_Reason_Code fy_match_block() {
    150                 return this_exception == 2 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
    151         }
    152 
    153         try(fy_try_block, fy_catch_block, fy_match_block);
    154 
    155         printf( "Fy exited normally\n" );
    156 }
    157 
    158 void fee() {
    159         raii_t a = { "Fee dtor" };
    160 
    161         void fee_try_block() {
    162                 raii_t b = { "Fee try dtor" };
    163 
    164                 fy();
    165 
    166                 printf("fy returned\n");
    167         }
    168 
    169         void fee_catch_block() {
    170                 printf("Fee caught exception\n");
    171         }
    172 
    173         _Unwind_Reason_Code fee_match_block() {
    174                 return this_exception == 3 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
    175         }
    176 
    177         try(fee_try_block, fee_catch_block, fee_match_block);
    178 
    179         printf( "Fee exited normally\n" );
    180 }
    181 // End not in main.cfa
    182 
    183129int main() {
    184130        raii_t a = { "Main dtor" };
    185131
    186         //for (unsigned int i = 0 ; i < 100000000 ; ++i)
    187         foo();
    188         fee();
     132        for (unsigned int i = 0 ; i < 100000000 ; ++i) foo();
    189133
    190134        printf("End of program reached\n");
  • doc/working/exception/reference.c

    rf94ca7e r2164637  
    114114// __builtin_eh_return_data_regno(^) ^=[0..3]? gives index.
    115115
    116 // Locally we also seem to have:
    117 _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);
    118116
    119117// GCC (Dwarf2 ?) Frame Layout Macros
    120 // See: https://gcc.gnu.org/onlinedocs/gccint/Frame-Layout.html
    121 // Include from: ???
     118// https://gcc.gnu.org/onlinedocs/gccint/Frame-Layout.html
    122119
    123120FIRST_PARAM_OFFSET(fundecl)
  • src/Common/PassVisitor.impl.h

    rf94ca7e r2164637  
    11#pragma once
    2 
    3 #define VISIT_START( node )  \
    4         call_previsit( node ); \
    5 
    6 #define VISIT_END( node )                \
    7         return call_postvisit( node ); \
    82
    93#define MUTATE_START( node )  \
    104        call_premutate( node ); \
    115
     6
    127#define MUTATE_END( type, node )                \
    138        return call_postmutate< type * >( node ); \
     
    1510
    1611#define VISIT_BODY( node )    \
    17         VISIT_START( node );  \
     12        call_previsit( node );  \
    1813        Visitor::visit( node ); \
    19         VISIT_END( node ); \
     14        call_postvisit( node ); \
    2015
    2116
     
    4439                if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); }
    4540                try {
    46                         (*i)->accept( *this );
     41                        *i = (*i)->accept( *this );
    4742                } catch ( SemanticError &e ) {
    4843                        errors.append( e );
     
    8378        ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
    8479
    85         maybeAccept( stmt, *this );
     80        Statement *newStmt = maybeVisit( stmt, *this );
    8681
    8782        StmtList_t* beforeStmts = get_beforeStmts();
    8883        StmtList_t* afterStmts  = get_afterStmts();
    8984
    90         if( empty(beforeStmts) && empty(afterStmts) ) { return stmt; }
     85        if( empty(beforeStmts) && empty(afterStmts) ) { return newStmt; }
    9186
    9287        CompoundStmt *compound = new CompoundStmt( noLabels );
    9388        if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); }
    94         compound->get_kids().push_back( stmt );
     89        compound->get_kids().push_back( newStmt );
    9590        if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); }
    9691        return compound;
     
    192187}
    193188
    194 //--------------------------------------------------------------------------
    195 // CompoundStmt
    196189template< typename pass_type >
    197190void PassVisitor< pass_type >::visit( CompoundStmt * node ) {
    198         VISIT_START( node );
    199         call_beginScope();
    200 
    201         visitStatementList( node->get_kids() );
    202 
    203         call_endScope();
    204         VISIT_END( node );
     191        VISIT_BODY( node );
    205192}
    206193
     
    216203}
    217204
    218 //--------------------------------------------------------------------------
    219 // ExprStmt
    220205template< typename pass_type >
    221206void PassVisitor< pass_type >::visit( ExprStmt * node ) {
    222         VISIT_START( node );
    223         call_beginScope();
    224 
    225         visitExpression( node->get_expr() );
    226 
    227         call_endScope();
    228         VISIT_END( node );
     207        VISIT_BODY( node );
    229208}
    230209
     
    243222}
    244223
    245 //--------------------------------------------------------------------------
    246 // IfStmt
    247224template< typename pass_type >
    248225void PassVisitor< pass_type >::visit( IfStmt * node ) {
    249         VISIT_START( node );
    250 
    251         visitExpression( node->get_condition() );
    252         node->set_thenPart ( visitStatement( node->get_thenPart() ) );
    253         node->set_elsePart ( visitStatement( node->get_elsePart() ) );
    254 
    255         VISIT_END( node );
     226        VISIT_BODY( node );
    256227}
    257228
     
    267238}
    268239
    269 //--------------------------------------------------------------------------
    270 // WhileStmt
    271240template< typename pass_type >
    272241void PassVisitor< pass_type >::visit( WhileStmt * node ) {
    273         VISIT_START( node );
    274 
    275         visitExpression( node->get_condition() );
    276         node->set_body( visitStatement( node->get_body() ) );
    277 
    278         VISIT_END( node );
     242        VISIT_BODY( node );
    279243}
    280244
     
    289253}
    290254
    291 //--------------------------------------------------------------------------
    292 // WhileStmt
     255
    293256template< typename pass_type >
    294257void PassVisitor< pass_type >::visit( ForStmt * node ) {
    295         VISIT_START( node );
    296 
    297         acceptAll( node->get_initialization(), *this );
    298         visitExpression( node->get_condition() );
    299         visitExpression( node->get_increment() );
    300         node->set_body( visitStatement( node->get_body() ) );
    301 
    302         VISIT_END( node );
     258        VISIT_BODY( node );
    303259}
    304260
     
    308264
    309265        mutateAll( node->get_initialization(), *this );
    310         node->set_condition( mutateExpression( node->get_condition() ) );
    311         node->set_increment( mutateExpression( node->get_increment() ) );
    312         node->set_body( mutateStatement( node->get_body() ) );
     266        node->set_condition(  mutateExpression( node->get_condition() ) );
     267        node->set_increment(  mutateExpression( node->get_increment() ) );
     268        node->set_body(  mutateStatement( node->get_body() ) );
    313269
    314270        MUTATE_END( Statement, node );
    315271}
    316272
    317 //--------------------------------------------------------------------------
    318 // SwitchStmt
    319273template< typename pass_type >
    320274void PassVisitor< pass_type >::visit( SwitchStmt * node ) {
    321         VISIT_START( node );
    322 
    323         visitExpression( node->get_condition() );
    324         visitStatementList( node->get_statements() );
    325 
    326         VISIT_END( node );
     275        VISIT_BODY( node );
    327276}
    328277
     
    337286}
    338287
    339 //--------------------------------------------------------------------------
    340 // SwitchStmt
    341288template< typename pass_type >
    342289void PassVisitor< pass_type >::visit( CaseStmt * node ) {
    343         VISIT_START( node );
    344        
    345         visitExpression( node->get_condition() );
    346         visitStatementList( node->get_statements() );
    347        
    348         VISIT_END( node );
     290        VISIT_BODY( node );
    349291}
    350292
     
    364306}
    365307
    366 //--------------------------------------------------------------------------
    367 // ReturnStmt
    368308template< typename pass_type >
    369309void PassVisitor< pass_type >::visit( ReturnStmt * node ) {
    370         VISIT_START( node );
    371 
    372         visitExpression( node->get_expr() );
    373 
    374         VISIT_END( node );
     310        VISIT_BODY( node );
    375311}
    376312
     
    384320}
    385321
    386 //--------------------------------------------------------------------------
    387 // TryStmt
    388322template< typename pass_type >
    389323void PassVisitor< pass_type >::visit( TryStmt * node ) {
    390         VISIT_START( node );
    391 
    392         maybeAccept( node->get_block(), *this );
    393         acceptAll( node->get_catchers(), *this );
    394 
    395         VISIT_END( node );
     324        VISIT_BODY( node );
    396325}
    397326
     
    406335}
    407336
    408 //--------------------------------------------------------------------------
    409 // CatchStmt
    410337template< typename pass_type >
    411338void PassVisitor< pass_type >::visit( CatchStmt * node ) {
    412         VISIT_START( node );
    413 
    414         node->set_body( visitStatement( node->get_body() ) );
    415         maybeAccept( node->get_decl(), *this );
    416 
    417         VISIT_END( node );
     339        VISIT_BODY( node );
    418340}
    419341
     
    453375}
    454376
    455 //--------------------------------------------------------------------------
    456 // UntypedExpr
    457377template< typename pass_type >
    458378void PassVisitor< pass_type >::visit( UntypedExpr * node ) {
    459         VISIT_START( node );
    460 
    461         for ( auto expr : node->get_args() ) {
    462                 visitExpression( expr );
    463         }
    464 
    465         VISIT_END( node );
     379        VISIT_BODY( node );
    466380}
    467381
     
    622536}
    623537
    624 //--------------------------------------------------------------------------
    625 // UntypedExpr
    626538template< typename pass_type >
    627539void PassVisitor< pass_type >::visit( StmtExpr * node ) {
    628         VISIT_START( node );
    629 
    630         // don't want statements from outer CompoundStmts to be added to this StmtExpr
    631         ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
    632         ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
    633         ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
    634 
    635         Visitor::visit( node );
    636 
    637         VISIT_END( node );
     540        VISIT_BODY( node );
    638541}
    639542
     
    737640}
    738641
    739 //--------------------------------------------------------------------------
    740 // UntypedExpr
    741642template< typename pass_type >
    742643void PassVisitor< pass_type >::visit( SingleInit * node ) {
    743         VISIT_START( node );
    744 
    745         visitExpression( node->get_value() );
    746 
    747         VISIT_END( node );
     644        VISIT_BODY( node );
    748645}
    749646
  • src/Makefile.am

    rf94ca7e r2164637  
    4343driver_cfa_cpp_SOURCES = ${SRC}
    4444driver_cfa_cpp_LDADD = ${LEXLIB} -ldl                   # yywrap
    45 driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14
     45driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -Werror -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14
    4646driver_cfa_cpp_LDFLAGS = -Xlinker -export-dynamic
    4747
  • src/Makefile.in

    rf94ca7e r2164637  
    447447driver_cfa_cpp_SOURCES = ${SRC}
    448448driver_cfa_cpp_LDADD = ${LEXLIB} -ldl                   # yywrap
    449 driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14
     449driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -Werror -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14
    450450driver_cfa_cpp_LDFLAGS = -Xlinker -export-dynamic
    451451all: $(BUILT_SOURCES)
  • src/Parser/lex.ll

    rf94ca7e r2164637  
    55 * file "LICENCE" distributed with Cforall.
    66 *
    7  * lex.ll --
     7 * lex.l --
    88 *
    99 * Author           : Peter A. Buhr
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Tue May 30 22:00:48 2017
    13  * Update Count     : 527
     12 * Last Modified On : Mon May 22 07:46:30 2017
     13 * Update Count     : 525
    1414 */
    1515
     
    235235long                    { KEYWORD_RETURN(LONG); }
    236236lvalue                  { KEYWORD_RETURN(LVALUE); }                             // CFA
    237 monitor                 { KEYWORD_RETURN(MONITOR); }                    // CFA
     237monitor         { KEYWORD_RETURN(MONITOR); }                    // CFA
    238238mutex                   { KEYWORD_RETURN(MUTEX); }                              // CFA
    239239_Noreturn               { KEYWORD_RETURN(NORETURN); }                   // C11
  • src/libcfa/stdlib

    rf94ca7e r2164637  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jun  2 15:51:03 2017
    13 // Update Count     : 218
     12// Last Modified On : Tue May 30 09:07:35 2017
     13// Update Count     : 164
    1414//
    1515
     
    2828//---------------------------------------
    2929
     30extern "C" { void * memset( void * dest, int c, size_t size ); } // use default C routine for void *
     31
    3032// allocation, non-array types
    3133static inline forall( dtype T | sized(T) ) T * malloc( void ) {
     
    3335        return (T *)(void *)malloc( (size_t)sizeof(T) );        // C malloc
    3436} // malloc
    35 
    36 extern "C" { void * calloc( size_t dim, size_t size ); } // default C routine
     37static inline forall( dtype T | sized(T) ) T * malloc( char fill ) {
     38        //printf( "X2\n" );
     39        T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) );     // C malloc
     40    return memset( ptr, (int)fill, sizeof(T) );                 // initial with fill value
     41} // malloc
     42
     43// allocation, array types
     44extern "C" { void * calloc( size_t dim, size_t size ); } // use default C routine for void *
    3745static inline forall( dtype T | sized(T) ) T * calloc( size_t dim ) {
    38         //printf( "X2\n" );
     46        //printf( "X3\n" );
    3947        return (T *)(void *)calloc( dim, sizeof(T) );           // C cmalloc
    4048}
    41 
    42 extern "C" { void * realloc( void * ptr, size_t size ); } // default C routine for void *
     49static inline forall( dtype T | sized(T) ) T * amalloc( size_t dim ) { // alternative name
     50        //printf( "X4\n" );
     51        return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
     52} // amalloc
     53static inline forall( dtype T | sized(T) ) T * amalloc( size_t dim, char fill ) { // alternative name
     54        //printf( "X5\n" );
     55        T * ptr = (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
     56    return memset( ptr, (int)fill, dim * sizeof(T) );
     57} // amalloc
     58
     59// resize, non-array types
     60extern "C" { void * realloc( void * ptr, size_t size ); } // use default C routine for void *
    4361static inline forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size ) {
    44         //printf( "X3\n" );
     62        //printf( "X5.5\n" );
    4563        return (T *)(void *)realloc( (void *)ptr, size );
    4664}
    47 
    48 extern "C" { void * memalign( size_t align, size_t size ); } // use default C routine for void *
    49 static inline forall( dtype T | sized(T) ) T * memalign( size_t align ) {
    50         //printf( "X4\n" );
    51         return (T *)memalign( align, sizeof(T) );
     65forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size, char fill );
     66static inline forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size ) { // alternative name
     67        //printf( "X7\n" );
     68        return realloc( ptr, size );
     69} // malloc
     70static inline forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size, char fill ) { // alternative name
     71        //printf( "X8\n" );
     72        return realloc( ptr, size, fill );
     73} // malloc
     74
     75// resize, array types
     76static inline forall( dtype T | sized(T) ) T * amalloc( T * ptr, size_t dim ) {
     77        //printf( "X9\n" );
     78        return malloc( ptr, dim * (size_t)sizeof(T) );
     79} // amalloc
     80static inline forall( dtype T | sized(T) ) T * amalloc( T * ptr, size_t dim, char fill ) {
     81        //printf( "X10\n" );
     82        return malloc( ptr, dim * (size_t)sizeof(T), fill );
     83} // amalloc
     84
     85// alignment, non-array types
     86extern "C" { void * memalign( size_t alignment, size_t size ); } // use default C routine for void *
     87static inline forall( dtype T | sized(T) ) T * memalign( size_t alignment ) {
     88        //printf( "X11\n" );
     89        return (T *)memalign( alignment, sizeof(T) );
    5290} // memalign
    53 
    54 static inline forall( dtype T | sized(T) ) T * aligned_alloc( size_t align ) {
    55         //printf( "X5\n" );
    56         return (T *)memalign( align, sizeof(T) );
     91static inline forall( dtype T | sized(T) ) T * memalign( size_t alignment, char fill ) {
     92        //printf( "X12\n" );
     93    T * ptr = (T *)memalign( alignment, sizeof(T) );
     94    return memset( ptr, (int)fill, sizeof(T) );
     95} // memalign
     96static inline forall( dtype T | sized(T) ) T * aligned_alloc( size_t alignment ) {
     97        //printf( "X13\n" );
     98        return (T *)memalign( alignment, sizeof(T) );
    5799} // aligned_alloc
    58 
    59 extern "C" { int posix_memalign( void ** ptr, size_t align, size_t size ); } // use default C routine for void *
    60 static inline forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t align ) {
    61         //printf( "X6\n" );
    62         return posix_memalign( (void **)ptr, align, sizeof(T) );
     100extern "C" { int posix_memalign( void ** ptr, size_t alignment, size_t size ); } // use default C routine for void *
     101static inline forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t alignment ) {
     102        //printf( "X14\n" );
     103        return posix_memalign( (void **)ptr, alignment, sizeof(T) );
    63104} // posix_memalign
    64105
    65 
    66 extern "C" { void * memset( void * dest, int c, size_t size ); } // use default C routine for void *
    67 
    68 static inline forall( dtype T | sized(T) ) T * alloc( void ) {
    69         //printf( "X7\n" );
    70         return (T *)(void *)malloc( (size_t)sizeof(T) );        // C malloc
    71 } // alloc
    72 static inline forall( dtype T | sized(T) ) T * alloc( char fill ) {
    73         //printf( "X8\n" );
    74         T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) );     // C malloc
    75     return memset( ptr, (int)fill, sizeof(T) );                 // initial with fill value
    76 } // alloc
    77 
    78 static inline forall( dtype T | sized(T) ) T * alloc( size_t dim ) {
    79         //printf( "X9\n" );
    80         return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
    81 } // alloc
    82 static inline forall( dtype T | sized(T) ) T * alloc( size_t dim, char fill ) {
    83         //printf( "X10\n" );
    84         T * ptr = (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
     106// alignment, array types
     107static inline forall( dtype T | sized(T) ) T * amemalign( size_t alignment, size_t dim ) {
     108        //printf( "X15\n" );
     109        return (T *)memalign( alignment, dim * sizeof(T) );
     110} // amemalign
     111static inline forall( dtype T | sized(T) ) T * amemalign( size_t alignment, size_t dim, char fill ) {
     112        //printf( "X16\n" );
     113    T * ptr = (T *)memalign( alignment, dim * sizeof(T) );
    85114    return memset( ptr, (int)fill, dim * sizeof(T) );
    86 } // alloc
    87 
    88 static inline forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim ) {
    89         //printf( "X11\n" );
    90         return (void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc
    91 } // alloc
    92 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill );
    93 
    94 static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align ) {
    95         //printf( "X13\n" );
    96         return (T *)memalign( align, sizeof(T) );
    97 } // align_alloc
    98 static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align, char fill ) {
    99         //printf( "X14\n" );
    100     T * ptr = (T *)memalign( align, sizeof(T) );
    101     return memset( ptr, (int)fill, sizeof(T) );
    102 } // align_alloc
    103 
    104 static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim ) {
    105         //printf( "X15\n" );
    106         return (T *)memalign( align, dim * sizeof(T) );
    107 } // align_alloc
    108 static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim, char fill ) {
    109         //printf( "X16\n" );
    110     T * ptr = (T *)memalign( align, dim * sizeof(T) );
    111     return memset( ptr, (int)fill, dim * sizeof(T) );
    112 } // align_alloc
    113 
     115} // amemalign
    114116
    115117// data, non-array types
     
    125127
    126128// data, array types
    127 static inline forall( dtype T | sized(T) ) T * memset( T dest[], size_t dim, char c ) {
     129static inline forall( dtype T | sized(T) ) T * amemset( T * dest, size_t dim, char c ) {
    128130        //printf( "X19\n" );
    129         return (void *)memset( dest, c, dim * sizeof(T) );      // C memset
    130 } // memset
    131 static inline forall( dtype T | sized(T) ) T * memcpy( T dest[], const T src[], size_t dim ) {
     131        return memset( dest, c, dim * sizeof(T) );
     132} // amemset
     133static inline forall( dtype T | sized(T) ) T * amemcpy( T * dest, const T * src, size_t dim ) {
    132134        //printf( "X20\n" );
    133         return (void *)memcpy( dest, src, dim * sizeof(T) ); // C memcpy
    134 } // memcpy
    135 
    136 // allocation/deallocation and constructor/destructor, non-array types
    137 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * new( Params p );
     135        return memcpy( dest, src, dim * sizeof(T) );
     136} // amemcpy
     137
     138// allocation/deallocation and constructor/destructor
     139forall( dtype T, ttype Params | sized(T) | { void ?{}(T *, Params); } ) T * new( Params p );
    138140forall( dtype T | { void ^?{}( T * ); } ) void delete( T * ptr );
    139141forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } ) void delete( T * ptr, Params rest );
    140 
    141 // allocation/deallocation and constructor/destructor, array types
    142 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * anew( size_t dim, Params p );
    143 forall( dtype T | sized(T) | { void ^?{}( T * ); } ) void adelete( size_t dim, T arr[] );
    144 forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } ) void adelete( size_t dim, T arr[], Params rest );
    145142
    146143//---------------------------------------
  • src/libcfa/stdlib.c

    rf94ca7e r2164637  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun  1 21:52:57 2017
    13 // Update Count     : 280
     12// Last Modified On : Tue May 30 09:07:56 2017
     13// Update Count     : 237
    1414//
    1515
     
    2828
    2929// resize, non-array types
    30 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill ) {
     30forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size, char fill ) { // alternative realloc with fill value
     31        //printf( "X6\n" );
    3132        size_t olen = malloc_usable_size( ptr );                        // current allocation
    32     char * nptr = (void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc
     33    char * nptr = (void *)realloc( (void *)ptr, size ); // C realloc
    3334        size_t nlen = malloc_usable_size( nptr );                       // new allocation
    3435        if ( nlen > olen ) {                                                            // larger ?
     
    3637        } //
    3738    return (T *)nptr;
    38 } // alloc
    39 
    40 // allocation/deallocation and constructor/destructor, non-array types
    41 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } )
     39} // realloc
     40
     41// allocation/deallocation and constructor/destructor
     42forall( dtype T, ttype Params | sized(T) | { void ?{}( T *, Params ); } )
    4243T * new( Params p ) {
    43         return (malloc()){ p };                                                         // run constructor
     44        return ((T *)malloc()){ p };
    4445} // new
    4546
    4647forall( dtype T | { void ^?{}( T * ); } )
    4748void delete( T * ptr ) {
    48         if ( ptr ) {                                                                            // ignore null
     49        if ( ptr ) {
    4950                ^ptr{};                                                                                 // run destructor
    5051                free( ptr );
     
    5455forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } )
    5556void delete( T * ptr, Params rest ) {
    56         if ( ptr ) {                                                                            // ignore null
     57        if ( ptr ) {
    5758                ^ptr{};                                                                                 // run destructor
    5859                free( ptr );
     
    6061        delete( rest );
    6162} // delete
    62 
    63 
    64 // allocation/deallocation and constructor/destructor, array types
    65 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } )
    66 T * anew( size_t dim, Params p ) {
    67         T *arr = alloc( dim );
    68         for ( unsigned int i = 0; i < dim; i += 1 ) {
    69                 (&arr[i]){ p };                                                                 // run constructor
    70         } // for
    71         return arr;
    72 } // anew
    73 
    74 forall( dtype T | sized(T) | { void ^?{}( T * ); } )
    75 void adelete( size_t dim, T arr[] ) {
    76         if ( arr ) {                                                                            // ignore null
    77                 for ( int i = dim - 1; i >= 0; i -= 1 ) {               // reverse allocation order, must be unsigned
    78                         ^(&arr[i]){};                                                           // run destructor
    79                 } // for
    80                 free( arr );
    81         } // if
    82 } // adelete
    83 
    84 forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } )
    85 void adelete( size_t dim, T arr[], Params rest ) {
    86         if ( arr ) {                                                                            // ignore null
    87                 for ( int i = dim - 1; i >= 0; i -= 1 ) {               // reverse allocation order, must be unsigned
    88                         ^(&arr[i]){};                                                           // run destructor
    89                 } // for
    90                 free( arr );
    91         } // if
    92         adelete( rest );
    93 } // adelete
    9463
    9564//---------------------------------------
  • src/tests/.expect/alloc.txt

    rf94ca7e r2164637  
    1 C   malloc 0xdeadbeef
    2 CFA malloc 0xdeadbeef
    3 CFA alloc 0xdeadbeef
    4 CFA alloc, fill 01010101
     1C   malloc deadbeef
     2CFA malloc 0
     3CFA malloc, fill 01010101
    54
    6 C   array calloc, fill 0
     5C   calloc
    760 0 0 0 0 0 0 0 0 0
    8 CFA array calloc, fill 0
     7CFA calloc
    980 0 0 0 0 0 0 0 0 0
    10 CFA array alloc, no fill
    11 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef
    12 CFA array alloc, fill 0x1
    13 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
     9CFA array malloc
     100 0 deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
     11CFA array malloc
     121010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101
    1413
    1514C   realloc
    16 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef
     15deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
    1716CFA realloc
    18 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
     17deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef 0 0 0 0 0 0 0 0 0 0
     18CFA realloc
     19deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
     20CFA resize malloc
     21deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
     22CFA resize malloc, fill
     23deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101
     24CFA resize malloc, fill
     25deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
    1926
    20 CFA resize alloc
    21 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef
    22 CFA resize array alloc
    23 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
    24 CFA resize array alloc
    25 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef
    26 CFA resize array alloc, fill
    27 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
    28 CFA resize array alloc, fill
    29 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
    30 CFA resize array alloc, fill
    31 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
     27CFA resize array malloc
     28deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef 0 0 0 0 0 0 0 0 0 0
     29CFA resize array malloc
     30deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
     31CFA resize array malloc, fill
     32deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101
     33CFA resize array malloc, fill
     34deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
    3235
    33 C   memalign 42 42.5
     36CFA aligned_alloc 42 42.5
    3437CFA memalign 42 42.5
    3538CFA posix_memalign 42 42.5
    36 CFA posix_memalign 42 42.5
    37 CFA aligned_alloc 42 42.5
    38 CFA align_alloc 42 42.5
    39 CFA align_alloc fill 0x1010101 0x1.1010101010101p-1007
     39CFA memalign fill 16843009 7.7486e-304
    4040
    41 CFA array align_alloc
    42 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5,
    43 CFA array align_alloc, fill
    44 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007,
     41CFA memalign array
     420 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0,
     43CFA memalign array
     441010101 7.7486e-304, 1010101 7.7486e-304, 1010101 7.7486e-304, 1010101 7.7486e-304, 1010101 7.7486e-304, 1010101 7.7486e-304, 1010101 7.7486e-304, 1010101 7.7486e-304, 1010101 7.7486e-304, 1010101 7.7486e-304,
    4545
    46 CFA memset 0x1010101 0x1.1010101010101p-1007
    47 CFA memcpy 0x1010101 0x1.1010101010101p-1007
     46CFA memset ffffffff -nan
     47CFA memcpy ffffffff -nan
    4848
    4949CFA array memset
    50 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007,
     50ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan,
    5151CFA memcpy
    52 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007,
    53 
    54 CFA new initialize
    55 42 42.5 42 42.5
    56 CFA array new initialize
    57 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5,
    58 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5,
    59 
     52deadbeef -17.2, deadbeef -17.2, deadbeef -17.2, deadbeef -17.2, deadbeef -17.2, deadbeef -17.2, deadbeef -17.2, deadbeef -17.2, deadbeef -17.2, deadbeef -17.2,
    6053pointer arithmetic 0
    61 CFA deep malloc 0xdeadbeef
     54CFA deep malloc deadbeef
    6255
    6356SHOULD FAIL
  • src/tests/alloc.c

    rf94ca7e r2164637  
    1010// Created On       : Wed Feb  3 07:56:22 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jun  2 15:13:03 2017
    13 // Update Count     : 316
     12// Last Modified On : Mon May 29 11:33:15 2017
     13// Update Count     : 228
    1414//
    1515
     
    1818#include <malloc.h>                                                                             // malloc_usable_size
    1919#include <stdint.h>                                                                             // uintptr_t
    20 #include <stdlib.h>                                                                             // posix_memalign
    2120} // extern
    2221#include <fstream>
     
    2928int main( void ) {
    3029    size_t dim = 10;
     30    struct S { int x; double y; } * s;
    3131    int * p;
    32         char fill = '\1';
    3332
    3433        // allocation, non-array types
     
    3635    p = (void *)malloc( sizeof(*p) );                                   // C malloc, type unsafe
    3736        *p = 0xdeadbeef;
    38         printf( "C   malloc %#x\n", *p );
     37        printf( "C   malloc %x\n", *p );
    3938    free( p );
    4039
    4140    p = malloc();                                                                               // CFA malloc, type safe
    42         *p = 0xdeadbeef;
    43         printf( "CFA malloc %#x\n", *p );
    44     free( p );
    45 
    46     p = alloc();                                                                                // CFA alloc, type safe
    47         *p = 0xdeadbeef;
    48         printf( "CFA alloc %#x\n", *p );
    49     free( p );
    50 
    51     p = alloc( fill );                                                                  // CFA alloc, fill
    52         printf( "CFA alloc, fill %08x\n", *p );
     41        printf( "CFA malloc %d\n", *p );
     42    free( p );
     43
     44    p = malloc( '\1' );                                                                 // CFA malloc, fill
     45        printf( "CFA malloc, fill %08x\n", *p );
    5346
    5447
     
    5750
    5851    p = calloc( dim, sizeof( *p ) );                                    // C array calloc, type unsafe
    59         printf( "C   array calloc, fill 0\n" );
    60         for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
     52        printf( "C   calloc\n" );
     53        for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
    6154        printf( "\n" );
    6255    free( p );
    6356
    6457    p = calloc( dim );                                                                  // CFA array calloc, type safe
    65         printf( "CFA array calloc, fill 0\n" );
    66         for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
    67         printf( "\n" );
    68     free( p );
    69 
    70     p = alloc( dim );                                                                   // CFA array alloc, type safe
    71         for ( int i = 0; i < dim; i += 1 ) { p[i] = 0xdeadbeef; }
    72         printf( "CFA array alloc, no fill\n" );
    73         for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
    74         printf( "\n" );
    75     free( p );
    76 
    77     p = alloc( 2 * dim, fill );                                                 // CFA array alloc, fill
    78         printf( "CFA array alloc, fill %#x\n", fill );
    79         for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%#x ", p[i] ); }
     58        printf( "CFA calloc\n" );
     59        for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
     60        printf( "\n" );
     61    free( p );
     62
     63    p = amalloc( dim );                                                                 // CFA array malloc, type safe
     64        printf( "CFA array malloc\n" );
     65        for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
     66        printf( "\n" );
     67    free( p );
     68
     69    p = amalloc( 2 * dim, '\1' );                                               // CFA array malloc, fill
     70        printf( "CFA array malloc\n" );
     71        for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
    8072        printf( "\n" );
    8173        // do not free
     
    8577        printf( "\n" );
    8678
    87     p = (void *)realloc( p, dim * sizeof(*p) );                 // C realloc
    88         for ( int i = 0; i < dim; i += 1 ) { p[i] = 0xdeadbeef; }
     79    p = (void *)realloc( p, dim * sizeof(*p) );                 // CFA realloc
    8980        printf( "C   realloc\n" );
    90         for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
     81        for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
    9182        printf( "\n" );
    9283
    9384    p = realloc( p, 2 * dim * sizeof(*p) );                             // CFA realloc
    94         for ( int i = dim; i < 2 * dim; i += 1 ) { p[i] = 0x1010101; }
    9585        printf( "CFA realloc\n" );
    96         for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%#x ", p[i] ); }
     86        for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
     87        printf( "\n" );
     88
     89    p = realloc( p, dim * sizeof(*p), '\1' );                   // CFA realloc
     90        printf( "CFA realloc\n" );
     91        for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
     92        printf( "\n" );
     93
     94    p = malloc( p, dim * sizeof(*p) );                                  // CFA malloc
     95        printf( "CFA resize malloc\n" );
     96        for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
     97        printf( "\n" );
     98
     99    p = malloc( p, 2 * dim * sizeof(*p), '\1' );                // CFA malloc, fill
     100        printf( "CFA resize malloc, fill\n" );
     101        for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
     102        printf( "\n" );
     103
     104    p = malloc( p, dim * sizeof(*p), '\1' );                    // CFA malloc, fill
     105        printf( "CFA resize malloc, fill\n" );
     106        for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
    97107        printf( "\n" );
    98108        // do not free
     
    102112        printf( "\n" );
    103113
    104     p = alloc( p, dim );                                                                // CFA resize array alloc
    105         for ( int i = 0; i < dim; i += 1 ) { p[i] = 0xdeadbeef; }
    106         printf( "CFA resize alloc\n" );
    107         for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
    108         printf( "\n" );
    109 
    110     p = alloc( p, 2 * dim );                                                    // CFA resize array alloc
    111         for ( int i = dim; i < 2 * dim; i += 1 ) { p[i] = 0x1010101; }
    112         printf( "CFA resize array alloc\n" );
    113         for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%#x ", p[i] ); }
    114         printf( "\n" );
    115 
    116     p = alloc( p, dim );                                                                // CFA array alloc
    117         printf( "CFA resize array alloc\n" );
    118         for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
    119         printf( "\n" );
    120 
     114    p = amalloc( p, 2 * dim );                                                  // CFA array malloc
     115        printf( "CFA resize array malloc\n" );
     116        for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
     117        printf( "\n" );
     118
     119    p = amalloc( p, dim );                                                              // CFA array malloc
     120        printf( "CFA resize array malloc\n" );
     121        for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
     122        printf( "\n" );
     123
     124    p = amalloc( p, 2 * dim, '\1' );                                    // CFA array malloc, fill
     125        printf( "CFA resize array malloc, fill\n" );
     126        for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
     127        printf( "\n" );
     128
     129    p = amalloc( p, dim, '\1' );                                                // CFA array malloc, fill
     130        printf( "CFA resize array malloc, fill\n" );
     131        for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
    121132        free( p );
    122         p = 0;
    123 
    124     p = alloc( p, dim, fill );                                                  // CFA array alloc, fill
    125         printf( "CFA resize array alloc, fill\n" );
    126         for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
    127         printf( "\n" );
    128 
    129     p = alloc( p, 2 * dim, fill );                                              // CFA array alloc, fill
    130         printf( "CFA resize array alloc, fill\n" );
    131         for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%#x ", p[i] ); }
    132         printf( "\n" );
    133 
    134     p = alloc( p, dim, fill );                                                  // CFA array alloc, fill
    135         printf( "CFA resize array alloc, fill\n" );
    136         for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] );; }
    137         printf( "\n" );
    138         free( p );
    139 
     133        printf( "\n" );
    140134
    141135    struct Struct { int x; double y; };
    142     Struct st, st1, sta[dim], sta1[dim], * stp, * stp1;
     136    Struct st, st1, sta[dim], sta1[dim], * stp;
     137
    143138
    144139        // alignment, non-array types
    145140        printf( "\n" );
     141
    146142        enum { Alignment = 128 };
    147 
    148     stp = (memalign( Alignment, sizeof( *stp ) ) ){ 42, 42.5 }; // C memalign
    149         assert( (uintptr_t)stp % Alignment == 0 );
    150         printf( "C   memalign %d %g\n", stp->x, stp->y );
    151     free( stp );
    152 
    153     stp = (memalign( Alignment )){ 42, 42.5 };                  // CFA memalign
     143    stp = aligned_alloc( Alignment );                                   // CFA aligned_alloc
     144        *stp = (Struct){ 42, 42.5 };
     145        assert( (uintptr_t)stp % Alignment == 0 );
     146        printf( "CFA aligned_alloc %d %g\n", stp->x, stp->y );
     147    free( stp );
     148
     149    stp = memalign( Alignment );                                                // CFA memalign
     150        *stp = (Struct){ 42, 42.5 };
    154151        assert( (uintptr_t)stp % Alignment == 0 );
    155152        printf( "CFA memalign %d %g\n", stp->x, stp->y );
    156     free( stp );
    157 
    158     posix_memalign( (void **)&stp, Alignment, sizeof( *stp ) ); // C posix_memalign
    159         *stp = (Struct){ 42, 42.5 };
    160         assert( (uintptr_t)stp % Alignment == 0 );
    161         printf( "CFA posix_memalign %d %g\n", stp->x, stp->y );
    162153    free( stp );
    163154
     
    168159    free( stp );
    169160
    170     stp = (aligned_alloc( Alignment )){ 42, 42.5 };             // CFA aligned_alloc
    171         assert( (uintptr_t)stp % Alignment == 0 );
    172         printf( "CFA aligned_alloc %d %g\n", stp->x, stp->y );
    173     free( stp );
    174 
    175     stp = (align_alloc( Alignment )){ 42, 42.5 };               // CFA align_alloc
    176         assert( (uintptr_t)stp % Alignment == 0 );
    177         printf( "CFA align_alloc %d %g\n", stp->x, stp->y );
    178     free( stp );
    179 
    180     stp = align_alloc( Alignment, fill );                               // CFA memalign, fill
    181         assert( (uintptr_t)stp % Alignment == 0 );
    182         printf( "CFA align_alloc fill %#x %a\n", stp->x, stp->y );
     161    stp = memalign( Alignment, '\1' );                                  // CFA memalign, fill
     162        assert( (uintptr_t)stp % Alignment == 0 );
     163        printf( "CFA memalign fill %d %g\n", stp->x, stp->y );
    183164    free( stp );
    184165
     
    187168        printf( "\n" );
    188169
    189     stp = align_alloc( Alignment, dim );                                // CFA array memalign
    190         assert( (uintptr_t)stp % Alignment == 0 );
    191         for ( int i = 0; i < dim; i += 1 ) { stp[i] = (Struct){ 42, 42.5 }; }
    192         printf( "CFA array align_alloc\n" );
    193         for ( int i = 0; i < dim; i += 1 ) { printf( "%d %g, ", stp[i].x, stp[i].y ); }
    194         printf( "\n" );
    195     free( stp );
    196 
    197     stp = align_alloc( Alignment, dim, fill );                  // CFA array memalign, fill
    198         assert( (uintptr_t)stp % Alignment == 0 );
    199         printf( "CFA array align_alloc, fill\n" );
    200         for ( int i = 0; i < dim; i += 1 ) { printf( "%#x %a, ", stp[i].x, stp[i].y ); }
     170    stp = amemalign( Alignment, 2 * dim );                              // CFA array memalign
     171        assert( (uintptr_t)stp % Alignment == 0 );
     172        printf( "CFA memalign array\n" );
     173        for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%x %g, ", stp[i].x, stp[i].y ); stp[i].x = 0Xdeadbeef, stp[i].y = -17.2; }
     174        printf( "\n" );
     175    free( stp );
     176
     177    stp = amemalign( Alignment, dim, '\1' );                    // CFA array memalign, fill
     178        assert( (uintptr_t)stp % Alignment == 0 );
     179        printf( "CFA memalign array\n" );
     180        for ( int i = 0; i < dim; i += 1 ) { printf( "%x %g, ", stp[i].x, stp[i].y ); stp[i].x = 0Xdeadbeef, stp[i].y = -17.2; }
    201181        printf( "\n" );
    202182    free( stp );
     
    206186        printf( "\n" );
    207187
    208     memset( &st, fill );                                                                // CFA memset, type safe
    209         printf( "CFA memset %#x %a\n", st.x, st.y );
    210     memcpy( &st1, &st );                                                                // CFA memcpy, type safe
    211         printf( "CFA memcpy %#x %a\n", st1.x, st1.y );
     188    stp = memset( &st, '\xff' );                                                // CFA memset, type safe
     189        printf( "CFA memset %x %g\n", st.x, st.y );
     190    stp = memcpy( &st1, &st );                                                  // CFA memcpy, type safe
     191        printf( "CFA memcpy %x %g\n", st1.x, st1.y );
    212192
    213193
     
    215195        printf( "\n" );
    216196
    217     memset( sta, dim, fill );                                                   // CFA array memset, type safe
     197    stp = amemset( sta, dim, '\xff' );                                  // CFA array memset, type safe
    218198        printf( "CFA array memset\n" );
    219         for ( int i = 0; i < dim; i += 1 ) { printf( "%#x %a, ", sta[i].x, sta[i].y ); }
    220         printf( "\n" );
    221 
    222     memcpy( sta1, sta, dim );                                                   // CFA array memcpy, type safe
     199        for ( int i = 0; i < dim; i += 1 ) { printf( "%x %g, ", sta[i].x, sta[i].y ); sta[i].x = 0Xdeadbeef, sta[i].y = -17.2; }
     200        printf( "\n" );
     201
     202    stp = amemcpy( sta1, sta, dim );                                    // CFA array memcpy, type safe
    223203        printf( "CFA memcpy\n" );
    224         for ( int i = 0; i < dim; i += 1 ) { printf( "%#x %a, ", sta1[i].x, sta1[i].y ); }
    225         printf( "\n" );
    226 
    227 
    228         // new, non-array types
    229         printf( "\n" );
    230 
    231         stp = new( 42, 42.5 );
    232         stp1 = new( 42, 42.5 );
    233         printf( "CFA new initialize\n%d %g %d %g\n", stp->x, stp->y, stp1->x, stp1->y );
    234         delete( stp, stp1 );
    235 
    236         // new, array types
    237         stp = anew( dim, 42, 42.5 );
    238         printf( "CFA array new initialize\n" );
    239         for ( int i = 0; i < dim; i += 1 ) { printf( "%d %g, ", stp[i].x, stp[i].y ); }
    240         printf( "\n" );
    241         stp1 = anew( dim, 42, 42.5 );
    242         for ( int i = 0; i < dim; i += 1 ) { printf( "%d %g, ", stp1[i].x, stp1[i].y ); }
    243         printf( "\n" );
    244         adelete( dim, stp, dim, stp1 );
    245 
    246         // extras
     204        for ( int i = 0; i < dim; i += 1 ) { printf( "%x %g, ", sta1[i].x, sta1[i].y ); sta1[i].x = 0Xdeadbeef, sta1[i].y = -17.2; }
    247205        printf( "\n" );
    248206
     
    253211    p = foo( bar( baz( malloc(), 0 ), 0 ), 0 );
    254212        *p = 0xdeadbeef;
    255         printf( "CFA deep malloc %#x\n", *p );
     213        printf( "CFA deep malloc %x\n", *p );
    256214    free( p );
    257215
    258216        stp = malloc();
    259217        printf( "\nSHOULD FAIL\n" );
    260     p = alloc( stp, dim * sizeof(*stp) );
     218    p = malloc( stp, dim * sizeof(*stp) );
    261219    p = memset( stp, 10 );
    262220    p = memcpy( &st1, &st );
Note: See TracChangeset for help on using the changeset viewer.