source: tests/init1.cfa @ d2b5d2d

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since d2b5d2d was b81fd95, checked in by Michael Brooks <mlbrooks@…>, 4 years ago

Fix bug where pointer and reference types allow unsound initialization and return. Fixes #189

There are two instances of the same basic change, which is using conversionCost instead of castCost for resolving...
A: an InitExpr?, always; affects variable initializations
B: a CastExpr?, for type-system-generated casts only; affects function returns

Changing the behaviour of the typechecker on initialization (do A) and cast (do B):
src/ResolvExpr/AlternativeFinder.cc
src/SynTree/Expression.h
testsinit1.*

Making type of string literal consistent with how C defines it (accommodate A):
src/Parser/ExpressionNode.cc

Making type system happy with incumbent use of void* (accommodate A):
libcfa/src/concurrency/kernel.cfa
libcfa/src/containers/list.hfa
tests/bugs/66.cfa
tests/avltree/avl1.cfa
tests/concurrent/signal/block.cfa
tests/searchsort.cfa

Making type system happy with incumbent plan-9 downcast (accommodate B):
libcfa/src/containers/list.hfa

Fixing previously incorrect constness of declarations (accommodate A):
tests/exceptions/defaults.cfa
libcfa/src/iostream.hfa

Fixing previously incorrect isGenerated classification of casts that desugaring introduces (accommodate B):
src/Concurrency/Keywords.cc
src/Concurrency/Waitfor.cc

Working around trac #207 (revealed by A):
tests/io2.cfa

Working around trac #208 (speculatively created by B):
libcfa/src/bits/locks.hfa
libcfa/src/concurrency/preemption.cfa

Misc:
tests/exceptions/conditional.cfa (accommodate A)

a _msg function for an exception was declared with wrong return type, so it was not compatible for assignment into the vtable instance

libcfa/src/stdlib.hfa

the compiler now prohibits a prior attempt to call a nonexistent realloc overload; calling alloc_align in its place

  • Property mode set to 100644
File size: 2.1 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2020 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// init1.cfa -- tests of initializing pointer- and reference-typed variables and returns
8//
9// Author           : Michael Brooks
10// Created On       : Thu Jul 16 22:00:00 2020
11// Last Modified By : Michael Brooks
12// Last Modified On : Thu Jul 16 22:00:00 2020
13// Update Count     : 1
14//
15
16void f() {
17
18    //
19    // setup
20    //
21
22    float x = 3.14;
23
24    float & rx = x;
25    float * px = &x;
26
27    const float & crx = x;
28    const float * cpx = &x;
29
30    //
31    // sound initializations
32    //
33
34    char * str1 = "hi";
35    const char * str2 = "hi";
36
37    float & rx2 = rx;
38    float * px2 = px;
39
40    const float & crx2 = crx;
41    const float * cpx2 = cpx;
42
43    //
44    // unsound initializations
45    //
46
47    // mismatched referenced type
48    int & ry = rx;
49    int * py = px;
50
51    // would discard refered constness (same float is referenced)
52    float & ry2 = crx;
53    float * py2 = cpx;
54}
55
56//
57// sound returns
58//
59
60char * f_str1() {
61    return "hi";
62}
63
64const char * f_str2() {
65    return "hi";
66}
67
68float & f_rx2 () {
69    float & rx = *0p;
70    return rx;
71}
72
73float * f_px2 () {
74    float * px = 0p;
75    return px;
76}
77
78const float & f_crx2 () {
79    float & rx = *0p;
80    return rx;
81}
82
83const float * f_cpx2 () {
84    float * px = 0p;
85    return px;
86}
87
88//
89// unsound returns
90//
91
92int & f_ry() {
93    float & rx = *0p;
94    return rx;               // mismatched referenced type
95}
96
97int * f_py() {
98    float * px = 0p;
99    return px;               // mismatched referenced type
100}
101
102float & f_ry2() {
103    const float & crx = *0p;
104    return crx;              // would discard refered constness (same float is referenced)
105}
106
107float * f_py2() {
108    const float * cpx = 0p;
109    return cpx;              // would discard refered constness (same float is referenced)
110}
111
112forall (dtype T, dtype S)
113T & anycvt( S & s ) {
114    return s;               // mismatched referenced type
115}
116
117forall (dtype T, dtype S)
118T * anycvt( S * s ) {
119    return s;               // mismatched referenced type
120}
Note: See TracBrowser for help on using the repository browser.