Skip to content

Commit e9e9e7f

Browse files
author
Christopher Bazley
committed
Revert support for _Optional at request of gz8cx4
1 parent 5cef7f3 commit e9e9e7f

13 files changed

Lines changed: 19 additions & 987 deletions

‎libtcc.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,6 @@ static const FlagDef options_W[] = {
17121712
{ offsetof(TCCState, warn_unsupported), 0, "unsupported" },
17131713
{ offsetof(TCCState, warn_implicit_function_declaration), WD_ALL, "implicit-function-declaration" },
17141714
{ offsetof(TCCState, warn_discarded_qualifiers), WD_ALL, "discarded-qualifiers" },
1715-
{ offsetof(TCCState, warn_null_to_nonoptional), 0, "null-to-nonoptional" },
17161715
{ 0, 0, NULL }
17171716
};
17181717

‎tcc-doc.texi‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,6 @@ Warn about implicit function declaration (missing prototype).
322322
@item -Wdiscarded-qualifiers
323323
Warn when const is dropped.
324324

325-
@item -Wnull-to-nonoptional
326-
Warn when a null pointer constant is implicitly converted to a pointer
327-
whose referenced type is not @code{_Optional}-qualified. This includes
328-
null arms of conditional expressions, using the eventual destination type.
329-
Explicit pointer casts suppress pending warnings from conditional arms.
330-
Casts forming null pointer constants, such as @code{(void *)0}, are still
331-
checked when implicitly converted. Disabled by default.
332-
333325
@item -Wunsupported
334326
Warn about unsupported GCC features that are ignored by TCC.
335327

@@ -702,19 +694,6 @@ supported.
702694

703695
@item @code{_Atomic} type qualifier for atomic types.
704696

705-
@item @code{_Optional} type qualifier as specified by draft ISO/IEC TS
706-
26716 (WG14 document N3951). Optional qualification is tracked at every
707-
type level and participates in the standard qualifier and conversion
708-
rules. TCC does not perform flow-sensitive analysis to determine whether
709-
an optional object is present.
710-
711-
The qualifier applies to the referenced type: a pointer is not
712-
optional merely because it can have a null value, any more
713-
than a pointer is @code{const} merely because it can reference an
714-
immutable object. A null pointer value can be copied, printed or
715-
converted, whereas an optional pointer object has neither value nor
716-
storage when the pointer through which it would be accessed is null.
717-
718697
@item @code{_Thread_local} storage-class specifier for thread-local
719698
storage. The GCC extension @code{__thread} is also supported.
720699

‎tcc.h‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ typedef struct SValue {
484484
unsigned short r; /* register + flags */
485485
unsigned short r2; /* second register, used for 'long long'
486486
type. If not used, set to VT_CONST */
487-
int nulls; /* 1 for an implicit null arm, -1 for a cast from a pointer */
488487
union {
489488
struct { int jtrue, jfalse; }; /* forward jmps */
490489
CValue c; /* constant, if VT_CONST */
@@ -767,7 +766,6 @@ struct TCCState {
767766
unsigned char warn_unsupported;
768767
unsigned char warn_implicit_function_declaration;
769768
unsigned char warn_discarded_qualifiers;
770-
unsigned char warn_null_to_nonoptional;
771769
#define WARN_ON 1 /* warning is on (-Woption) */
772770
unsigned char warn_num; /* temp var for tcc_warning_c() */
773771

@@ -1066,20 +1064,18 @@ struct filespec {
10661064
#define VT_CONSTANT 0x0100 /* const modifier */
10671065
#define VT_VOLATILE 0x0200 /* volatile modifier */
10681066
#define VT_RESTRICT 0x0400 /* restrict modifier */
1069-
#define VT_OPTIONAL 0x0800 /* _Optional qualifier */
1070-
/* Keep qualifier bits together for A32 data-processing immediates. */
1071-
#define VT_QUAL (VT_CONSTANT | VT_VOLATILE | VT_RESTRICT | VT_OPTIONAL)
1072-
#define VT_VLA 0x1000 /* VLA type (also has VT_PTR) */
1067+
#define VT_QUAL (VT_CONSTANT | VT_VOLATILE | VT_RESTRICT)
1068+
#define VT_VLA 0x0800 /* VLA type (also has VT_PTR) */
10731069
#define VT_ARRAY_MASK (VT_ARRAY | VT_VLA)
1074-
#define VT_LONG 0x2000 /* long type (also has VT_INT rsp. VT_LLONG) */
1070+
#define VT_LONG 0x1000 /* long type (also has VT_INT rsp. VT_LLONG) */
10751071

10761072
/* storage */
1077-
#define VT_EXTERN 0x00004000 /* extern definition */
1078-
#define VT_STATIC 0x00008000 /* static variable */
1079-
#define VT_TYPEDEF 0x00010000 /* typedef definition */
1080-
#define VT_INLINE 0x00020000 /* inline definition */
1081-
#define VT_TLS 0x00040000 /* thread-local storage */
1082-
/* currently unused: 0x00080000 */
1073+
#define VT_EXTERN 0x00002000 /* extern definition */
1074+
#define VT_STATIC 0x00004000 /* static variable */
1075+
#define VT_TYPEDEF 0x00008000 /* typedef definition */
1076+
#define VT_INLINE 0x00010000 /* inline definition */
1077+
#define VT_TLS 0x00020000 /* thread-local storage */
1078+
/* currently unused: 0x000[48]0000 */
10831079

10841080
#define VT_STRUCT_SHIFT 20 /* shift for bitfield shift values (32 - 2*6) */
10851081
#define VT_STRUCT_MASK (((1U << (6+6)) - 1) << VT_STRUCT_SHIFT | VT_BITFIELD)

‎tccgen.c‎

Lines changed: 5 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,6 @@ static void gen_cast(CType *type);
137137
static void gen_cast_s(int t);
138138
static inline CType *pointed_type(CType *type);
139139
static void check_restrict_type(CType *type);
140-
static void unqualify_optional(CType *type);
141-
static void unqualify_optional_target(CType *type);
142-
static int is_optional_type(CType *type);
143140
static int type_qualifiers(CType *type);
144141
static void parse_btype_qualify(CType *type, int qualifiers);
145142
static int is_compatible_types(CType *type1, CType *type2);
@@ -899,7 +896,6 @@ static void vsetc(CType *type, int r, CValue *vc)
899896
vtop->r2 = VT_CONST;
900897
vtop->c = *vc;
901898
vtop->sym = NULL;
902-
vtop->nulls = 0;
903899
}
904900

905901
ST_FUNC void vswap(void)
@@ -2684,8 +2680,6 @@ static void type_to_str(char *buf, int buf_size,
26842680
if (bt != VT_PTR) {
26852681
if (t & VT_RESTRICT)
26862682
pstrcat(buf, buf_size, "restrict ");
2687-
if (t & VT_OPTIONAL)
2688-
pstrcat(buf, buf_size, "_Optional ");
26892683
if (t & VT_VOLATILE)
26902684
pstrcat(buf, buf_size, "volatile ");
26912685
if (t & VT_CONSTANT)
@@ -2790,8 +2784,6 @@ static void type_to_str(char *buf, int buf_size,
27902784
pstrcat(buf1, sizeof(buf1), "const ");
27912785
if (t & VT_VOLATILE)
27922786
pstrcat(buf1, sizeof(buf1), "volatile ");
2793-
if (t & VT_OPTIONAL)
2794-
pstrcat(buf1, sizeof(buf1), "_Optional ");
27952787
if (varstr)
27962788
pstrcat(buf1, sizeof(buf1), varstr);
27972789
type_to_str(buf, buf_size, &s->type, buf1);
@@ -2839,11 +2831,6 @@ static inline int is_null_pointer(SValue *p)
28392831
);
28402832
}
28412833

2842-
static int has_implicit_null(SValue *sv)
2843-
{
2844-
return sv->nulls > 0 || (sv->nulls == 0 && is_null_pointer(sv));
2845-
}
2846-
28472834
/* compare function types. OLD functions match any new functions */
28482835
static int is_compatible_func(CType *type1, CType *type2)
28492836
{
@@ -3079,8 +3066,6 @@ ST_FUNC void gen_op(int op)
30793066
CType type1, combtype;
30803067
int op_class = op;
30813068

3082-
vtop[-1].nulls = vtop->nulls = 0;
3083-
30843069
if (op == TOK_SHR || op == TOK_SAR || op == TOK_SHL)
30853070
op_class = SHIFT_OP;
30863071
else if (TOK_ISCOND(op)) /* == != > ... */
@@ -3095,13 +3080,11 @@ ST_FUNC void gen_op(int op)
30953080
if (bt1 == VT_FUNC || bt2 == VT_FUNC) {
30963081
if (bt2 == VT_FUNC) {
30973082
mk_pointer(&vtop->type);
3098-
unqualify_optional_target(&vtop->type);
30993083
gaddrof();
31003084
}
31013085
if (bt1 == VT_FUNC) {
31023086
vswap();
31033087
mk_pointer(&vtop->type);
3104-
unqualify_optional_target(&vtop->type);
31053088
gaddrof();
31063089
vswap();
31073090
}
@@ -3161,7 +3144,6 @@ ST_FUNC void gen_op(int op)
31613144
gen_opic(op);
31623145
}
31633146
type1.t &= ~(VT_ARRAY|VT_VLA);
3164-
unqualify_optional_target(&type1);
31653147
/* put again type if gen_opic() swaped operands */
31663148
vtop->type = type1;
31673149
}
@@ -3628,26 +3610,6 @@ static CType *qualifier_type(CType *type)
36283610
return type;
36293611
}
36303612

3631-
static void unqualify_optional(CType *type)
3632-
{
3633-
if (is_optional_type(type))
3634-
qualifier_type(type)->t &= ~VT_OPTIONAL;
3635-
}
3636-
3637-
static void unqualify_optional_target(CType *type)
3638-
{
3639-
if (!is_optional_type(pointed_type(type)))
3640-
return;
3641-
/* The target symbol may be shared with another type. */
3642-
type->ref = sym_push(SYM_FIELD, &type->ref->type, 0, type->ref->c);
3643-
unqualify_optional(pointed_type(type));
3644-
}
3645-
3646-
static int is_optional_type(CType *type)
3647-
{
3648-
return !!(type_qualifiers(type) & VT_OPTIONAL);
3649-
}
3650-
36513613
/* Array qualifiers are represented on the element type. */
36523614
static int type_qualifiers(CType *type)
36533615
{
@@ -3688,17 +3650,12 @@ static void cast_error(CType *st, CType *dt)
36883650
/* verify type compatibility to store vtop in 'dt' type */
36893651
static void verify_assign_cast(CType *dt)
36903652
{
3691-
CType *st, *type1, *type2, ct;
3653+
CType *st, *type1, *type2;
36923654
int dbt, sbt, qualwarn, lvl;
36933655

36943656
st = &vtop->type; /* source type */
36953657
dbt = dt->t & VT_BTYPE;
36963658
sbt = st->t & VT_BTYPE;
3697-
if (dbt == VT_PTR && !(dt->t & VT_ARRAY)
3698-
&& !is_optional_type(pointed_type(dt)) && has_implicit_null(vtop))
3699-
tcc_warning_c(warn_null_to_nonoptional)(
3700-
"null pointer constant converted to pointer with non-optional target type");
3701-
vtop->nulls = 0;
37023659
if (dt->t & VT_CONSTANT)
37033660
tcc_warning("assignment of read-only location");
37043661
switch(dbt) {
@@ -3720,14 +3677,9 @@ static void verify_assign_cast(CType *dt)
37203677
if (sbt == VT_PTR)
37213678
type2 = pointed_type(st);
37223679
else if (sbt == VT_FUNC)
3723-
type2 = st;
3680+
type2 = st; /* a function is implicitly a function pointer */
37243681
else
37253682
goto error;
3726-
if ((st->t & VT_ARRAY_MASK) || sbt == VT_FUNC) {
3727-
ct = *type2;
3728-
unqualify_optional(&ct);
3729-
type2 = &ct;
3730-
}
37313683
if (is_compatible_types(type1, type2))
37323684
break;
37333685
for (qualwarn = lvl = 0;; ++lvl) {
@@ -4718,9 +4670,6 @@ static void struct_decl(CType *type, int u)
47184670
}
47194671
}
47204672
}
4721-
if (is_optional_type(&type1))
4722-
tcc_error("field '%s' has optional-qualified type",
4723-
get_tok_str(v, NULL));
47244673
if (type_size(&type1, &align) < 0) {
47254674
if ((u == VT_STRUCT) && (type1.t & VT_ARRAY) && c)
47264675
flexible = 1;
@@ -4956,12 +4905,6 @@ static int parse_btype(CType *type, AttributeDef *ad, int ignore_label)
49564905
goto basic_type2;
49574906
}
49584907
break;
4959-
case TOK_OPTIONAL:
4960-
type->t = t;
4961-
parse_btype_qualify(type, VT_OPTIONAL);
4962-
t = type->t;
4963-
next();
4964-
break;
49654908
case TOK_CONST1:
49664909
case TOK_CONST2:
49674910
case TOK_CONST3:
@@ -5131,12 +5074,8 @@ static inline void convert_parameter_type(CType *pt)
51315074
/* apply the conversions required for an expression value */
51325075
static inline void convert_expression_type(CType *pt)
51335076
{
5134-
int converts = (pt->t & VT_BTYPE) == VT_FUNC || (pt->t & VT_ARRAY_MASK);
5135-
51365077
pt->t &= ~VT_QUAL;
51375078
convert_parameter_type(pt);
5138-
if (converts)
5139-
unqualify_optional_target(pt);
51405079
}
51415080

51425081
ST_FUNC CString* parse_asm_str(void)
@@ -5217,9 +5156,6 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td)
52175156
if (n < TOK_UIDENT)
52185157
expect("identifier");
52195158
convert_parameter_type(&pt);
5220-
if (is_optional_type(&pt))
5221-
tcc_error("parameter '%s' has optional-qualified type",
5222-
get_tok_str(n & ~SYM_FIELD, NULL));
52235159
arg_size += (type_size(&pt, &align) + PTR_SIZE - 1) / PTR_SIZE;
52245160
/* these symbols may be evaluated for VLArrays (see below, under
52255161
nocode_wanted) Example: int func(int a, int b[++a]); */
@@ -5276,10 +5212,6 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td)
52765212
in parameter decls. The '*' as well, and then even only
52775213
in prototypes (not function defs). */
52785214
switch (tok) {
5279-
case TOK_OPTIONAL:
5280-
array_qualifiers |= VT_OPTIONAL;
5281-
next();
5282-
continue;
52835215
case TOK_CONST1: case TOK_CONST2: case TOK_CONST3:
52845216
array_qualifiers |= VT_CONSTANT;
52855217
next();
@@ -5414,9 +5346,6 @@ static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td)
54145346
case TOK__Atomic:
54155347
qualifiers |= VT_ATOMIC;
54165348
goto redo;
5417-
case TOK_OPTIONAL:
5418-
qualifiers |= VT_OPTIONAL;
5419-
goto redo;
54205349
case TOK_CONST1:
54215350
case TOK_CONST2:
54225351
case TOK_CONST3:
@@ -5855,9 +5784,7 @@ ST_FUNC void unary(void)
58555784
skip(')');
58565785
/* check ISOC99 compound literal */
58575786
if (tok == '{') {
5858-
if (is_optional_type(&type))
5859-
tcc_error("compound literal has optional-qualified type");
5860-
/* data is allocated locally by default */
5787+
/* data is allocated locally by default */
58615788
if (global_expr)
58625789
r = VT_CONST;
58635790
else
@@ -5872,10 +5799,7 @@ ST_FUNC void unary(void)
58725799
return;
58735800
} else {
58745801
unary();
5875-
/* Remember a pointer operand even if the cast folds to 0. */
5876-
r = vtop->nulls < 0 || (vtop->type.t & VT_BTYPE) == VT_PTR;
58775802
gen_cast(&type);
5878-
vtop->nulls = r ? -1 : 0;
58795803
}
58805804
} else if (tok == '{') {
58815805
int saved_nocode_wanted = nocode_wanted;
@@ -5909,7 +5833,6 @@ ST_FUNC void unary(void)
59095833
next();
59105834
unary();
59115835
indir();
5912-
vtop->nulls = 0;
59135836
break;
59145837
case '&':
59155838
next();
@@ -5924,7 +5847,6 @@ ST_FUNC void unary(void)
59245847
test_lvalue();
59255848
if (vtop->sym)
59265849
vtop->sym->a.addrtaken = 1;
5927-
unqualify_optional(&vtop->type);
59285850
mk_pointer(&vtop->type);
59295851
gaddrof();
59305852
break;
@@ -6773,7 +6695,6 @@ static int is_cond_bool(SValue *sv)
67736695
static void expr_cond(void)
67746696
{
67756697
int tt, u, r1, r2, rc, t1, t2, islv, c, g;
6776-
int nulls;
67776698
SValue sv;
67786699
CType type;
67796700

@@ -6826,9 +6747,6 @@ static void expr_cond(void)
68266747
if ((vtop->type.t & VT_BTYPE) == VT_FUNC)
68276748
mk_pointer(&vtop->type);
68286749

6829-
/* Defer null-arm warnings until the destination type is known. */
6830-
nulls = has_implicit_null(&sv) || has_implicit_null(vtop);
6831-
68326750
/* cast operands to correct type according to ISOC rules */
68336751
if (!combine_types(&type, &sv, vtop, '?'))
68346752
type_incompatibility_error(&sv.type, &vtop->type,
@@ -6901,7 +6819,6 @@ static void expr_cond(void)
69016819

69026820
if (islv)
69036821
indir();
6904-
vtop->nulls = (type.t & VT_BTYPE) == VT_PTR ? nulls : 0;
69056822
}
69066823
}
69076824

@@ -8443,11 +8360,9 @@ static void decl_initializer(init_params *p, CType *type, unsigned long c, int f
84438360
&& (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST
84448361
&& vtop->c.i == 0
84458362
&& btype_size(type->t & VT_BTYPE) /* not for fp constants */
8446-
) {
8447-
if ((type->t & VT_BTYPE) == VT_PTR)
8448-
verify_assign_cast(type);
8363+
)
84498364
vpop();
8450-
} else
8365+
else
84518366
init_putv(p, type, c);
84528367
}
84538368
}
@@ -9023,9 +8938,6 @@ static int decl(int l)
90238938
type = btype;
90248939
ad = adbase;
90258940
type_decl(&type, &ad, &v, l == VT_CMP ? TYPE_DIRECT | TYPE_PARAM : TYPE_DIRECT);
9026-
if (!(type.t & VT_TYPEDEF) && is_optional_type(&type))
9027-
tcc_error("'%s' has optional-qualified type",
9028-
get_tok_str(v, NULL));
90298941
/*ptype("decl", &type, v);*/
90308942
if ((type.t & VT_BTYPE) == VT_FUNC) {
90318943
if ((type.t & VT_STATIC) && (l != VT_CONST))

‎tcctok.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
DEF(TOK_STATIC, "static")
2121
DEF(TOK_UNSIGNED, "unsigned")
2222
DEF(TOK__Atomic, "_Atomic")
23-
DEF(TOK_OPTIONAL, "_Optional")
2423
DEF(TOK_CONST1, "const")
2524
DEF(TOK_CONST2, "__const") /* gcc keyword */
2625
DEF(TOK_CONST3, "__const__") /* gcc keyword */

0 commit comments

Comments
 (0)