tccgen.c: merge more function attributes

Merge function attributes with those given given for the
prototype, also handle post-decl appearance such as

    void func() __attribute__((noreturn))
    {
    }

Also, some test fixes (unrelated).
This commit is contained in:
grischka 2020-05-13 11:14:53 +02:00
parent 7bb5454ef3
commit 4429cef9f6
3 changed files with 17 additions and 3 deletions

View file

@ -1507,6 +1507,12 @@ static void merge_funcattr(struct FuncAttr *fa, struct FuncAttr *fa1)
fa->func_type = fa1->func_type; fa->func_type = fa1->func_type;
if (fa1->func_args && !fa->func_args) if (fa1->func_args && !fa->func_args)
fa->func_args = fa1->func_args; fa->func_args = fa1->func_args;
if (fa1->func_noreturn)
fa->func_noreturn = 1;
if (fa1->func_ctor)
fa->func_ctor = 1;
if (fa1->func_dtor)
fa->func_dtor = 1;
} }
/* Merge attributes. */ /* Merge attributes. */
@ -1563,9 +1569,11 @@ static void patch_type(Sym *sym, CType *type)
} }
if (0 == (type->t & VT_EXTERN)) { if (0 == (type->t & VT_EXTERN)) {
struct FuncAttr f = sym->type.ref->f;
/* put complete type, use static from prototype */ /* put complete type, use static from prototype */
sym->type.t = (type->t & ~(VT_STATIC|VT_INLINE)) | static_proto; sym->type.t = (type->t & ~(VT_STATIC|VT_INLINE)) | static_proto;
sym->type.ref = type->ref; sym->type.ref = type->ref;
merge_funcattr(&sym->type.ref->f, &f);
} else { } else {
sym->type.t &= ~VT_INLINE | static_proto; sym->type.t &= ~VT_INLINE | static_proto;
} }
@ -8201,9 +8209,13 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym)
sym->type = int_type; sym->type = int_type;
} }
/* apply post-declaraton attributes */
merge_funcattr(&type.ref->f, &ad.f);
/* put function symbol */ /* put function symbol */
type.t &= ~VT_EXTERN; type.t &= ~VT_EXTERN;
sym = external_sym(v, &type, 0, &ad); sym = external_sym(v, &type, 0, &ad);
/* static inline functions are just recorded as a kind /* static inline functions are just recorded as a kind
of macro. Their code will be emitted at the end of of macro. Their code will be emitted at the end of
the compilation unit only if they are used */ the compilation unit only if they are used */

View file

@ -229,7 +229,7 @@ abitest-cc.exe: abitest.c $(LIBTCC)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w $(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w
abitest-tcc.exe: abitest.c libtcc.c abitest-tcc.exe: abitest.c libtcc.c
$(TCC) -o $@ $^ $(LIBS) $(TCC) -o $@ $^ $(NATIVE_DEFINES) $(LIBS)
abitest-% : abitest-%.exe abitest-% : abitest-%.exe
@echo ------------ $@ ------------ @echo ------------ $@ ------------

View file

@ -36,9 +36,11 @@ endif
ifeq (-$(CONFIG_WIN32)-$(CONFIG_i386)$(CONFIG_arm)-,--yes-) ifeq (-$(CONFIG_WIN32)-$(CONFIG_i386)$(CONFIG_arm)-,--yes-)
SKIP += 95_bitfields%.test # type_align is different on 32bit-non-windows SKIP += 95_bitfields%.test # type_align is different on 32bit-non-windows
endif endif
ifneq (-$(CONFIG_WIN32)$(CONFIG_WIN64)-,--) ifeq (-$(CONFIG_WIN32)-,-yes-)
SKIP += 106_pthread.test # No pthread support SKIP += 106_pthread.test # No pthread support
SKIP += 114_bound_signal.test endif
ifneq (-$(CONFIG_WIN32)-$(findstring $(GCC_MAJOR),3 4)-,---)
SKIP += 114_bound_signal.test # not on windows or older linuxes
endif endif
# Some tests might need arguments # Some tests might need arguments