From c8c82d3a333201010b1c0cf8aad804e721aec94e Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 4 Jan 2022 11:26:03 +0100 Subject: Removed two more false positive gcc -O2 warnings. Improved c_forpair macro. Updated checkauto.ll. --- include/stc/ccommon.h | 6 +++--- include/stc/cdeq.h | 6 ++++-- include/stc/cvec.h | 6 ++++-- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index e21589ea..dd2401a9 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -148,9 +148,9 @@ STC_INLINE uint64_t c_hash64(const void* key, size_t len) { ; it.ref != it##_end_.ref; C##_next(&it)) #define c_forpair(key, val, C, cnt) /* structured binding */ \ - for (struct {C##_iter _it, _end; C##_key key; C##_mapped val;} \ - _ = {C##_begin(&cnt), C##_end(&cnt)} \ - ; _._it.ref != _._end.ref && (_.key = _._it.ref->first, _.val = _._it.ref->second, true) \ + for (struct {C##_iter _it; C##_value* _endref; C##_key key; C##_mapped val;} \ + _ = {C##_begin(&cnt), C##_end(&cnt).ref} \ + ; _._it.ref != _._endref && (_.key = _._it.ref->first, _.val = _._it.ref->second, true) \ ; C##_next(&_._it)) #define c_forrange(...) c_MACRO_OVERLOAD(c_forrange, __VA_ARGS__) diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index 74662043..fb4f4ffb 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -249,9 +249,11 @@ _cx_memb(_shrink_to_fit)(_cx_self *self) { STC_DEF void _cx_memb(_drop)(_cx_self* self) { + struct cdeq_rep* rep = cdeq_rep_(self); + // second test to supress gcc -O2 warn: -Wfree-nonheap-object + if (rep->cap == 0 || rep == &_cdeq_sentinel) return; _cx_memb(_clear)(self); - if (cdeq_rep_(self)->cap) - c_free(cdeq_rep_(self)); + c_free(rep); } STC_DEF size_t diff --git a/include/stc/cvec.h b/include/stc/cvec.h index ec2db626..9da2ba56 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -254,9 +254,11 @@ _cx_memb(_clear)(_cx_self* self) { STC_DEF void _cx_memb(_drop)(_cx_self* self) { - if (!cvec_rep_(self)->cap) return; + struct cvec_rep* rep = cvec_rep_(self); + // second test to supress gcc -O2 warn: -Wfree-nonheap-object + if (rep->cap == 0 || rep == &_cvec_sentinel) return; _cx_memb(_clear)(self); - c_free(cvec_rep_(self)); + c_free(rep); } STC_DEF bool -- cgit v1.2.3