Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH v2 0/2] GCC 10 fix warnings
@ 2020-11-27 12:43 Artem Starshov
  2020-11-27 12:43 ` [Tarantool-patches] [PATCH v2 1/2] sql: fix build with GCC 10 Artem Starshov
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Artem Starshov @ 2020-11-27 12:43 UTC (permalink / raw)
  To: Alexander Turenko; +Cc: tarantool-patches

Artem Starshov (2):
  sql: fix build with GCC 10
  bitset: replace zero-length array with flexible-array member

 src/box/sql/select.c    | 56 +++++++++++++++++++----------------------
 src/lib/bitset/bitset.h |  2 +-
 2 files changed, 27 insertions(+), 31 deletions(-)

Issue: https://github.com/tarantool/tarantool/issues/4966
Branch: https://github.com/tarantool/tarantool/tree/artemreyt/gh-4966-gcc10-warns
-- 
2.28.0

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Tarantool-patches] [PATCH v2 1/2] sql: fix build with GCC 10
  2020-11-27 12:43 [Tarantool-patches] [PATCH v2 0/2] GCC 10 fix warnings Artem Starshov
@ 2020-11-27 12:43 ` Artem Starshov
  2020-12-09  8:43   ` Leonid Vasiliev
  2020-11-27 12:43 ` [Tarantool-patches] [PATCH v2 2/2] bitset: replace zero-length array with flexible-array member Artem Starshov
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Artem Starshov @ 2020-11-27 12:43 UTC (permalink / raw)
  To: Alexander Turenko; +Cc: tarantool-patches

GCC 10 produces the following error:
cc1: warning: function may return address of local variable [-Wreturn-local-addr]

Fix it.

Part-of #4966
---
Got LGTM from Nikita Pettik:
https://lists.tarantool.org/pipermail/tarantool-patches/2020-November/020940.html

 src/box/sql/select.c | 56 ++++++++++++++++++++------------------------
 1 file changed, 26 insertions(+), 30 deletions(-)

diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index b0554a172..5d4b2f624 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -154,56 +154,52 @@ sqlSelectNew(Parse * pParse,	/* Parsing context */
 		 Expr * pLimit,		/* LIMIT value.  NULL means not used */
 		 Expr * pOffset)	/* OFFSET value.  NULL means no offset */
 {
-	Select *pNew;
 	Select standin;
 	sql *db = pParse->db;
-	pNew = sqlDbMallocRawNN(db, sizeof(*pNew));
-	if (pNew == 0) {
-		assert(db->mallocFailed);
-		pNew = &standin;
-	}
 	if (pEList == 0) {
 		struct Expr *expr = sql_expr_new_anon(db, TK_ASTERISK);
 		if (expr == NULL)
 			pParse->is_aborted = true;
 		pEList = sql_expr_list_append(db, NULL, expr);
 	}
-	pNew->pEList = pEList;
-	pNew->op = TK_SELECT;
-	pNew->selFlags = selFlags;
-	pNew->iLimit = 0;
-	pNew->iOffset = 0;
+	standin.pEList = pEList;
+	standin.op = TK_SELECT;
+	standin.selFlags = selFlags;
+	standin.iLimit = 0;
+	standin.iOffset = 0;
 #ifdef SQL_DEBUG
-	pNew->zSelName[0] = 0;
+	standin.zSelName[0] = 0;
 	if ((pParse->sql_flags & SQL_SelectTrace) != 0)
 		sqlSelectTrace = 0xfff;
 	else
 		sqlSelectTrace = 0;
 #endif
-	pNew->addrOpenEphm[0] = -1;
-	pNew->addrOpenEphm[1] = -1;
-	pNew->nSelectRow = 0;
+	standin.addrOpenEphm[0] = -1;
+	standin.addrOpenEphm[1] = -1;
+	standin.nSelectRow = 0;
 	if (pSrc == 0)
 		pSrc = sqlDbMallocZero(db, sizeof(*pSrc));
-	pNew->pSrc = pSrc;
-	pNew->pWhere = pWhere;
-	pNew->pGroupBy = pGroupBy;
-	pNew->pHaving = pHaving;
-	pNew->pOrderBy = pOrderBy;
-	pNew->pPrior = 0;
-	pNew->pNext = 0;
-	pNew->pLimit = pLimit;
-	pNew->pOffset = pOffset;
-	pNew->pWith = 0;
+	standin.pSrc = pSrc;
+	standin.pWhere = pWhere;
+	standin.pGroupBy = pGroupBy;
+	standin.pHaving = pHaving;
+	standin.pOrderBy = pOrderBy;
+	standin.pPrior = 0;
+	standin.pNext = 0;
+	standin.pLimit = pLimit;
+	standin.pOffset = pOffset;
+	standin.pWith = 0;
 	assert(pOffset == 0 || pLimit != 0 || pParse->is_aborted
 	       || db->mallocFailed != 0);
+	Select *pNew = sqlDbMallocRawNN(db, sizeof(*pNew));
 	if (db->mallocFailed) {
-		clearSelect(db, pNew, pNew != &standin);
-		pNew = 0;
-	} else {
-		assert(pNew->pSrc != 0 || pParse->is_aborted);
+		clearSelect(db, &standin, 0);
+		if (pNew != NULL)
+			sqlDbFree(db, pNew);
+		return NULL;
 	}
-	assert(pNew != &standin);
+	assert(standin.pSrc != 0 || pParse->is_aborted);
+	memcpy(pNew, &standin, sizeof(standin));
 	return pNew;
 }
 
-- 
2.28.0

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Tarantool-patches] [PATCH v2 2/2] bitset: replace zero-length array with flexible-array member
  2020-11-27 12:43 [Tarantool-patches] [PATCH v2 0/2] GCC 10 fix warnings Artem Starshov
  2020-11-27 12:43 ` [Tarantool-patches] [PATCH v2 1/2] sql: fix build with GCC 10 Artem Starshov
@ 2020-11-27 12:43 ` Artem Starshov
  2020-11-30 12:47   ` Aleksandr Lyapunov
  2020-12-09  8:11   ` Leonid Vasiliev
  2020-12-01 14:16 ` [Tarantool-patches] [PATCH v2 0/2] GCC 10 fix warnings Alexander V. Tikhonov
  2020-12-16 11:47 ` Kirill Yukhin
  3 siblings, 2 replies; 11+ messages in thread
From: Artem Starshov @ 2020-11-27 12:43 UTC (permalink / raw)
  To: Alexander Turenko; +Cc: tarantool-patches

Zero-lenght arrays are GNU C extension.
There's ISO C99 flexible array member, which
is preffered mechanism to declare variable-length types.

Flexible array member allows us to avoid applying sizeof
operator cause it's incomplete type, so it will be an error
at compile time. There're any moments else why it's better
way to implement such structures via FAM:
https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

In this issue it fixed gcc 10 warning:
"warning: writing 1 byte into
a region of size 0 [-Wstringop-overflow=]"

Closes #4966
Closes #5564
---
 src/lib/bitset/bitset.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lib/bitset/bitset.h b/src/lib/bitset/bitset.h
index e2ae4f5f6..775de5c07 100644
--- a/src/lib/bitset/bitset.h
+++ b/src/lib/bitset/bitset.h
@@ -69,7 +69,7 @@ struct tt_bitset_page {
 	size_t first_pos;
 	rb_node(struct tt_bitset_page) node;
 	size_t cardinality;
-	uint8_t data[0];
+	uint8_t data[];
 };
 
 typedef rb_tree(struct tt_bitset_page) tt_bitset_pages_t;
-- 
2.28.0

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Tarantool-patches] [PATCH v2 2/2] bitset: replace zero-length array with flexible-array member
  2020-11-27 12:43 ` [Tarantool-patches] [PATCH v2 2/2] bitset: replace zero-length array with flexible-array member Artem Starshov
@ 2020-11-30 12:47   ` Aleksandr Lyapunov
  2020-12-09  8:11   ` Leonid Vasiliev
  1 sibling, 0 replies; 11+ messages in thread
From: Aleksandr Lyapunov @ 2020-11-30 12:47 UTC (permalink / raw)
  To: Artem Starshov, Alexander Turenko; +Cc: tarantool-patches

Hi!
Thank for the patch!
LGTM now.
I'm glad we found such a laconic solution.

On 11/27/20 3:43 PM, Artem Starshov wrote:
> Zero-lenght arrays are GNU C extension.
> There's ISO C99 flexible array member, which
> is preffered mechanism to declare variable-length types.
>
> Flexible array member allows us to avoid applying sizeof
> operator cause it's incomplete type, so it will be an error
> at compile time. There're any moments else why it's better
> way to implement such structures via FAM:
> https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
>
> In this issue it fixed gcc 10 warning:
> "warning: writing 1 byte into
> a region of size 0 [-Wstringop-overflow=]"
>
> Closes #4966
> Closes #5564
> ---
>   src/lib/bitset/bitset.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/lib/bitset/bitset.h b/src/lib/bitset/bitset.h
> index e2ae4f5f6..775de5c07 100644
> --- a/src/lib/bitset/bitset.h
> +++ b/src/lib/bitset/bitset.h
> @@ -69,7 +69,7 @@ struct tt_bitset_page {
>   	size_t first_pos;
>   	rb_node(struct tt_bitset_page) node;
>   	size_t cardinality;
> -	uint8_t data[0];
> +	uint8_t data[];
>   };
>   
>   typedef rb_tree(struct tt_bitset_page) tt_bitset_pages_t;

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Tarantool-patches] [PATCH v2 0/2] GCC 10 fix warnings
  2020-11-27 12:43 [Tarantool-patches] [PATCH v2 0/2] GCC 10 fix warnings Artem Starshov
  2020-11-27 12:43 ` [Tarantool-patches] [PATCH v2 1/2] sql: fix build with GCC 10 Artem Starshov
  2020-11-27 12:43 ` [Tarantool-patches] [PATCH v2 2/2] bitset: replace zero-length array with flexible-array member Artem Starshov
@ 2020-12-01 14:16 ` Alexander V. Tikhonov
  2020-12-02  0:27   ` Alexander V. Tikhonov
  2020-12-16 11:47 ` Kirill Yukhin
  3 siblings, 1 reply; 11+ messages in thread
From: Alexander V. Tikhonov @ 2020-12-01 14:16 UTC (permalink / raw)
  To: Artem Starshov; +Cc: tarantool-patches

Hi Artem, thanks for the patch. I see some strange results in OSX and
FreeBSD testings. It looks like a flaky results, but they are new and
happens to often, even rerun of the testings could not resolve it.
Seems that some new hidden issue appeared. Feel free to contact me to
analyze it [1].

[1] - https://gitlab.com/tarantool/tarantool/-/pipelines/222165041/builds

> On Fri, Nov 27, 2020 at 03:43:08PM +0300, Artem Starshov via Tarantool-patches wrote:
> Artem Starshov (2):
>   sql: fix build with GCC 10
>   bitset: replace zero-length array with flexible-array member
> 
>  src/box/sql/select.c    | 56 +++++++++++++++++++----------------------
>  src/lib/bitset/bitset.h |  2 +-
>  2 files changed, 27 insertions(+), 31 deletions(-)
> 
> Issue: https://github.com/tarantool/tarantool/issues/4966
> Branch: https://github.com/tarantool/tarantool/tree/artemreyt/gh-4966-gcc10-warns
> -- 
> 2.28.0
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Tarantool-patches] [PATCH v2 0/2] GCC 10 fix warnings
  2020-12-01 14:16 ` [Tarantool-patches] [PATCH v2 0/2] GCC 10 fix warnings Alexander V. Tikhonov
@ 2020-12-02  0:27   ` Alexander V. Tikhonov
  0 siblings, 0 replies; 11+ messages in thread
From: Alexander V. Tikhonov @ 2020-12-02  0:27 UTC (permalink / raw)
  To: Alexander V. Tikhonov, Artem Starshov; +Cc: tarantool-patches

Hi Artem, as I see rebase helped to resolve the issues [1], patch LGTM.

[1] - https://gitlab.com/tarantool/tarantool/-/pipelines/223855440

On Tue, Dec 01, 2020 at 05:16:12PM +0300, Alexander V. Tikhonov via Tarantool-patches wrote:
> Hi Artem, thanks for the patch. I see some strange results in OSX and
> FreeBSD testings. It looks like a flaky results, but they are new and
> happens to often, even rerun of the testings could not resolve it.
> Seems that some new hidden issue appeared. Feel free to contact me to
> analyze it [1].
> 
> [1] - https://gitlab.com/tarantool/tarantool/-/pipelines/222165041/builds
> 
> > On Fri, Nov 27, 2020 at 03:43:08PM +0300, Artem Starshov via Tarantool-patches wrote:
> > Artem Starshov (2):
> >   sql: fix build with GCC 10
> >   bitset: replace zero-length array with flexible-array member
> > 
> >  src/box/sql/select.c    | 56 +++++++++++++++++++----------------------
> >  src/lib/bitset/bitset.h |  2 +-
> >  2 files changed, 27 insertions(+), 31 deletions(-)
> > 
> > Issue: https://github.com/tarantool/tarantool/issues/4966
> > Branch: https://github.com/tarantool/tarantool/tree/artemreyt/gh-4966-gcc10-warns
> > -- 
> > 2.28.0
> > 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Tarantool-patches] [PATCH v2 2/2] bitset: replace zero-length array with flexible-array member
  2020-11-27 12:43 ` [Tarantool-patches] [PATCH v2 2/2] bitset: replace zero-length array with flexible-array member Artem Starshov
  2020-11-30 12:47   ` Aleksandr Lyapunov
@ 2020-12-09  8:11   ` Leonid Vasiliev
  1 sibling, 0 replies; 11+ messages in thread
From: Leonid Vasiliev @ 2020-12-09  8:11 UTC (permalink / raw)
  To: Artem Starshov, Alexander Turenko; +Cc: tarantool-patches

Hi! Thank you for the patch!
LGTM

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Tarantool-patches] [PATCH v2 1/2] sql: fix build with GCC 10
  2020-11-27 12:43 ` [Tarantool-patches] [PATCH v2 1/2] sql: fix build with GCC 10 Artem Starshov
@ 2020-12-09  8:43   ` Leonid Vasiliev
  2020-12-09  9:04     ` Artem
  0 siblings, 1 reply; 11+ messages in thread
From: Leonid Vasiliev @ 2020-12-09  8:43 UTC (permalink / raw)
  To: Artem Starshov, Alexander Turenko; +Cc: tarantool-patches

Hi! Thank you for the patch.
Looks correctly, but I have one question:

On 27.11.2020 15:43, Artem Starshov via Tarantool-patches wrote:
> GCC 10 produces the following error:
> cc1: warning: function may return address of local variable [-Wreturn-local-addr]
> 
> Fix it.
> 
> Part-of #4966
> ---
> Got LGTM from Nikita Pettik:
> https://lists.tarantool.org/pipermail/tarantool-patches/2020-November/020940.html
> 
>   src/box/sql/select.c | 56 ++++++++++++++++++++------------------------
>   1 file changed, 26 insertions(+), 30 deletions(-)
> 
> diff --git a/src/box/sql/select.c b/src/box/sql/select.c
> index b0554a172..5d4b2f624 100644
> --- a/src/box/sql/select.c
> +++ b/src/box/sql/select.c
> @@ -154,56 +154,52 @@ sqlSelectNew(Parse * pParse,	/* Parsing context */
>   		 Expr * pLimit,		/* LIMIT value.  NULL means not used */
>   		 Expr * pOffset)	/* OFFSET value.  NULL means no offset */
>   {
> -	Select *pNew;
>   	Select standin;
>   	sql *db = pParse->db;
> -	pNew = sqlDbMallocRawNN(db, sizeof(*pNew));
> -	if (pNew == 0) {

1) Why can't we return NULL if malloc has failed and don't work with
standin at all?

> -		assert(db->mallocFailed);
> -		pNew = &standin;
> -	}
>   	if (pEList == 0) {
>   		struct Expr *expr = sql_expr_new_anon(db, TK_ASTERISK);
>   		if (expr == NULL)
>   			pParse->is_aborted = true;
>   		pEList = sql_expr_list_append(db, NULL, expr);
>   	}
> -	pNew->pEList = pEList;
> -	pNew->op = TK_SELECT;
> -	pNew->selFlags = selFlags;
> -	pNew->iLimit = 0;
> -	pNew->iOffset = 0;
> +	standin.pEList = pEList;
> +	standin.op = TK_SELECT;
> +	standin.selFlags = selFlags;
> +	standin.iLimit = 0;
> +	standin.iOffset = 0;
>   #ifdef SQL_DEBUG
> -	pNew->zSelName[0] = 0;
> +	standin.zSelName[0] = 0;
>   	if ((pParse->sql_flags & SQL_SelectTrace) != 0)
>   		sqlSelectTrace = 0xfff;
>   	else
>   		sqlSelectTrace = 0;
>   #endif
> -	pNew->addrOpenEphm[0] = -1;
> -	pNew->addrOpenEphm[1] = -1;
> -	pNew->nSelectRow = 0;
> +	standin.addrOpenEphm[0] = -1;
> +	standin.addrOpenEphm[1] = -1;
> +	standin.nSelectRow = 0;
>   	if (pSrc == 0)
>   		pSrc = sqlDbMallocZero(db, sizeof(*pSrc));
> -	pNew->pSrc = pSrc;
> -	pNew->pWhere = pWhere;
> -	pNew->pGroupBy = pGroupBy;
> -	pNew->pHaving = pHaving;
> -	pNew->pOrderBy = pOrderBy;
> -	pNew->pPrior = 0;
> -	pNew->pNext = 0;
> -	pNew->pLimit = pLimit;
> -	pNew->pOffset = pOffset;
> -	pNew->pWith = 0;
> +	standin.pSrc = pSrc;
> +	standin.pWhere = pWhere;
> +	standin.pGroupBy = pGroupBy;
> +	standin.pHaving = pHaving;
> +	standin.pOrderBy = pOrderBy;
> +	standin.pPrior = 0;
> +	standin.pNext = 0;
> +	standin.pLimit = pLimit;
> +	standin.pOffset = pOffset;
> +	standin.pWith = 0;
>   	assert(pOffset == 0 || pLimit != 0 || pParse->is_aborted
>   	       || db->mallocFailed != 0);
> +	Select *pNew = sqlDbMallocRawNN(db, sizeof(*pNew));
>   	if (db->mallocFailed) {
> -		clearSelect(db, pNew, pNew != &standin);
> -		pNew = 0;
> -	} else {
> -		assert(pNew->pSrc != 0 || pParse->is_aborted);
> +		clearSelect(db, &standin, 0);
> +		if (pNew != NULL)
> +			sqlDbFree(db, pNew);
> +		return NULL;
>   	}
> -	assert(pNew != &standin);
> +	assert(standin.pSrc != 0 || pParse->is_aborted);
> +	memcpy(pNew, &standin, sizeof(standin));
>   	return pNew;
>   }
>   
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Tarantool-patches] [PATCH v2 1/2] sql: fix build with GCC 10
  2020-12-09  8:43   ` Leonid Vasiliev
@ 2020-12-09  9:04     ` Artem
  2020-12-09 10:07       ` Leonid Vasiliev
  0 siblings, 1 reply; 11+ messages in thread
From: Artem @ 2020-12-09  9:04 UTC (permalink / raw)
  To: Leonid Vasiliev; +Cc: tarantool-patches

Hi, thanks for your letter!

Answering your question: we can't just return NULL, because this 
function, oddly enough,

is responsible for clearing of its arguments in case of allocation 
failure. In order to clean

them correctly we need to fill `Select` structure and invoke 
`clearSelect` for it.

09.12.2020 11:43, Leonid Vasiliev пишет:
> Hi! Thank you for the patch.
> Looks correctly, but I have one question:
>
> On 27.11.2020 15:43, Artem Starshov via Tarantool-patches wrote:
>> GCC 10 produces the following error:
>> cc1: warning: function may return address of local variable 
>> [-Wreturn-local-addr]
>>
>> Fix it.
>>
>> Part-of #4966
>> ---
>> Got LGTM from Nikita Pettik:
>> https://lists.tarantool.org/pipermail/tarantool-patches/2020-November/020940.html 
>>
>>
>>   src/box/sql/select.c | 56 ++++++++++++++++++++------------------------
>>   1 file changed, 26 insertions(+), 30 deletions(-)
>>
>> diff --git a/src/box/sql/select.c b/src/box/sql/select.c
>> index b0554a172..5d4b2f624 100644
>> --- a/src/box/sql/select.c
>> +++ b/src/box/sql/select.c
>> @@ -154,56 +154,52 @@ sqlSelectNew(Parse * pParse,    /* Parsing 
>> context */
>>            Expr * pLimit,        /* LIMIT value.  NULL means not used */
>>            Expr * pOffset)    /* OFFSET value.  NULL means no offset */
>>   {
>> -    Select *pNew;
>>       Select standin;
>>       sql *db = pParse->db;
>> -    pNew = sqlDbMallocRawNN(db, sizeof(*pNew));
>> -    if (pNew == 0) {
>
> 1) Why can't we return NULL if malloc has failed and don't work with
> standin at all?
>
>> -        assert(db->mallocFailed);
>> -        pNew = &standin;
>> -    }
>>       if (pEList == 0) {
>>           struct Expr *expr = sql_expr_new_anon(db, TK_ASTERISK);
>>           if (expr == NULL)
>>               pParse->is_aborted = true;
>>           pEList = sql_expr_list_append(db, NULL, expr);
>>       }
>> -    pNew->pEList = pEList;
>> -    pNew->op = TK_SELECT;
>> -    pNew->selFlags = selFlags;
>> -    pNew->iLimit = 0;
>> -    pNew->iOffset = 0;
>> +    standin.pEList = pEList;
>> +    standin.op = TK_SELECT;
>> +    standin.selFlags = selFlags;
>> +    standin.iLimit = 0;
>> +    standin.iOffset = 0;
>>   #ifdef SQL_DEBUG
>> -    pNew->zSelName[0] = 0;
>> +    standin.zSelName[0] = 0;
>>       if ((pParse->sql_flags & SQL_SelectTrace) != 0)
>>           sqlSelectTrace = 0xfff;
>>       else
>>           sqlSelectTrace = 0;
>>   #endif
>> -    pNew->addrOpenEphm[0] = -1;
>> -    pNew->addrOpenEphm[1] = -1;
>> -    pNew->nSelectRow = 0;
>> +    standin.addrOpenEphm[0] = -1;
>> +    standin.addrOpenEphm[1] = -1;
>> +    standin.nSelectRow = 0;
>>       if (pSrc == 0)
>>           pSrc = sqlDbMallocZero(db, sizeof(*pSrc));
>> -    pNew->pSrc = pSrc;
>> -    pNew->pWhere = pWhere;
>> -    pNew->pGroupBy = pGroupBy;
>> -    pNew->pHaving = pHaving;
>> -    pNew->pOrderBy = pOrderBy;
>> -    pNew->pPrior = 0;
>> -    pNew->pNext = 0;
>> -    pNew->pLimit = pLimit;
>> -    pNew->pOffset = pOffset;
>> -    pNew->pWith = 0;
>> +    standin.pSrc = pSrc;
>> +    standin.pWhere = pWhere;
>> +    standin.pGroupBy = pGroupBy;
>> +    standin.pHaving = pHaving;
>> +    standin.pOrderBy = pOrderBy;
>> +    standin.pPrior = 0;
>> +    standin.pNext = 0;
>> +    standin.pLimit = pLimit;
>> +    standin.pOffset = pOffset;
>> +    standin.pWith = 0;
>>       assert(pOffset == 0 || pLimit != 0 || pParse->is_aborted
>>              || db->mallocFailed != 0);
>> +    Select *pNew = sqlDbMallocRawNN(db, sizeof(*pNew));
>>       if (db->mallocFailed) {
>> -        clearSelect(db, pNew, pNew != &standin);
>> -        pNew = 0;
>> -    } else {
>> -        assert(pNew->pSrc != 0 || pParse->is_aborted);
>> +        clearSelect(db, &standin, 0);
>> +        if (pNew != NULL)
>> +            sqlDbFree(db, pNew);
>> +        return NULL;
>>       }
>> -    assert(pNew != &standin);
>> +    assert(standin.pSrc != 0 || pParse->is_aborted);
>> +    memcpy(pNew, &standin, sizeof(standin));
>>       return pNew;
>>   }
>>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Tarantool-patches] [PATCH v2 1/2] sql: fix build with GCC 10
  2020-12-09  9:04     ` Artem
@ 2020-12-09 10:07       ` Leonid Vasiliev
  0 siblings, 0 replies; 11+ messages in thread
From: Leonid Vasiliev @ 2020-12-09 10:07 UTC (permalink / raw)
  To: Artem; +Cc: tarantool-patches



On 09.12.2020 12:04, Artem wrote:
> Hi, thanks for your letter!
> 
> Answering your question: we can't just return NULL, because this 
> function, oddly enough,
> 
> is responsible for clearing of its arguments in case of allocation 
> failure. In order to clean
> 
> them correctly we need to fill `Select` structure and invoke 
> `clearSelect` for it.
> 

Yep. You are right!
LGTM.

> 09.12.2020 11:43, Leonid Vasiliev пишет:
>> Hi! Thank you for the patch.
>> Looks correctly, but I have one question:
>>
>> On 27.11.2020 15:43, Artem Starshov via Tarantool-patches wrote:
>>> GCC 10 produces the following error:
>>> cc1: warning: function may return address of local variable 
>>> [-Wreturn-local-addr]
>>>
>>> Fix it.
>>>
>>> Part-of #4966
>>> ---
>>> Got LGTM from Nikita Pettik:
>>> https://lists.tarantool.org/pipermail/tarantool-patches/2020-November/020940.html 
>>>
>>>
>>>   src/box/sql/select.c | 56 ++++++++++++++++++++------------------------
>>>   1 file changed, 26 insertions(+), 30 deletions(-)
>>>
>>> diff --git a/src/box/sql/select.c b/src/box/sql/select.c
>>> index b0554a172..5d4b2f624 100644
>>> --- a/src/box/sql/select.c
>>> +++ b/src/box/sql/select.c
>>> @@ -154,56 +154,52 @@ sqlSelectNew(Parse * pParse,    /* Parsing 
>>> context */
>>>            Expr * pLimit,        /* LIMIT value.  NULL means not used */
>>>            Expr * pOffset)    /* OFFSET value.  NULL means no offset */
>>>   {
>>> -    Select *pNew;
>>>       Select standin;
>>>       sql *db = pParse->db;
>>> -    pNew = sqlDbMallocRawNN(db, sizeof(*pNew));
>>> -    if (pNew == 0) {
>>
>> 1) Why can't we return NULL if malloc has failed and don't work with
>> standin at all?
>>
>>> -        assert(db->mallocFailed);
>>> -        pNew = &standin;
>>> -    }
>>>       if (pEList == 0) {
>>>           struct Expr *expr = sql_expr_new_anon(db, TK_ASTERISK);
>>>           if (expr == NULL)
>>>               pParse->is_aborted = true;
>>>           pEList = sql_expr_list_append(db, NULL, expr);
>>>       }
>>> -    pNew->pEList = pEList;
>>> -    pNew->op = TK_SELECT;
>>> -    pNew->selFlags = selFlags;
>>> -    pNew->iLimit = 0;
>>> -    pNew->iOffset = 0;
>>> +    standin.pEList = pEList;
>>> +    standin.op = TK_SELECT;
>>> +    standin.selFlags = selFlags;
>>> +    standin.iLimit = 0;
>>> +    standin.iOffset = 0;
>>>   #ifdef SQL_DEBUG
>>> -    pNew->zSelName[0] = 0;
>>> +    standin.zSelName[0] = 0;
>>>       if ((pParse->sql_flags & SQL_SelectTrace) != 0)
>>>           sqlSelectTrace = 0xfff;
>>>       else
>>>           sqlSelectTrace = 0;
>>>   #endif
>>> -    pNew->addrOpenEphm[0] = -1;
>>> -    pNew->addrOpenEphm[1] = -1;
>>> -    pNew->nSelectRow = 0;
>>> +    standin.addrOpenEphm[0] = -1;
>>> +    standin.addrOpenEphm[1] = -1;
>>> +    standin.nSelectRow = 0;
>>>       if (pSrc == 0)
>>>           pSrc = sqlDbMallocZero(db, sizeof(*pSrc));
>>> -    pNew->pSrc = pSrc;
>>> -    pNew->pWhere = pWhere;
>>> -    pNew->pGroupBy = pGroupBy;
>>> -    pNew->pHaving = pHaving;
>>> -    pNew->pOrderBy = pOrderBy;
>>> -    pNew->pPrior = 0;
>>> -    pNew->pNext = 0;
>>> -    pNew->pLimit = pLimit;
>>> -    pNew->pOffset = pOffset;
>>> -    pNew->pWith = 0;
>>> +    standin.pSrc = pSrc;
>>> +    standin.pWhere = pWhere;
>>> +    standin.pGroupBy = pGroupBy;
>>> +    standin.pHaving = pHaving;
>>> +    standin.pOrderBy = pOrderBy;
>>> +    standin.pPrior = 0;
>>> +    standin.pNext = 0;
>>> +    standin.pLimit = pLimit;
>>> +    standin.pOffset = pOffset;
>>> +    standin.pWith = 0;
>>>       assert(pOffset == 0 || pLimit != 0 || pParse->is_aborted
>>>              || db->mallocFailed != 0);
>>> +    Select *pNew = sqlDbMallocRawNN(db, sizeof(*pNew));
>>>       if (db->mallocFailed) {
>>> -        clearSelect(db, pNew, pNew != &standin);
>>> -        pNew = 0;
>>> -    } else {
>>> -        assert(pNew->pSrc != 0 || pParse->is_aborted);
>>> +        clearSelect(db, &standin, 0);
>>> +        if (pNew != NULL)
>>> +            sqlDbFree(db, pNew);
>>> +        return NULL;
>>>       }
>>> -    assert(pNew != &standin);
>>> +    assert(standin.pSrc != 0 || pParse->is_aborted);
>>> +    memcpy(pNew, &standin, sizeof(standin));
>>>       return pNew;
>>>   }
>>>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Tarantool-patches] [PATCH v2 0/2] GCC 10 fix warnings
  2020-11-27 12:43 [Tarantool-patches] [PATCH v2 0/2] GCC 10 fix warnings Artem Starshov
                   ` (2 preceding siblings ...)
  2020-12-01 14:16 ` [Tarantool-patches] [PATCH v2 0/2] GCC 10 fix warnings Alexander V. Tikhonov
@ 2020-12-16 11:47 ` Kirill Yukhin
  3 siblings, 0 replies; 11+ messages in thread
From: Kirill Yukhin @ 2020-12-16 11:47 UTC (permalink / raw)
  To: Artem Starshov; +Cc: tarantool-patches, Alexander Turenko

Hello,

On 27 Nov 15:43, Artem Starshov via Tarantool-patches wrote:
> Artem Starshov (2):
>   sql: fix build with GCC 10
>   bitset: replace zero-length array with flexible-array member
> 
>  src/box/sql/select.c    | 56 +++++++++++++++++++----------------------
>  src/lib/bitset/bitset.h |  2 +-
>  2 files changed, 27 insertions(+), 31 deletions(-)
> 
> Issue: https://github.com/tarantool/tarantool/issues/4966
> Branch: https://github.com/tarantool/tarantool/tree/artemreyt/gh-4966-gcc10-warns

I've checked your patchset into 1.10 (top only), 2.5, 2.6 and master.

--
Regards, Kirill Yukhin

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-12-16 11:47 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-27 12:43 [Tarantool-patches] [PATCH v2 0/2] GCC 10 fix warnings Artem Starshov
2020-11-27 12:43 ` [Tarantool-patches] [PATCH v2 1/2] sql: fix build with GCC 10 Artem Starshov
2020-12-09  8:43   ` Leonid Vasiliev
2020-12-09  9:04     ` Artem
2020-12-09 10:07       ` Leonid Vasiliev
2020-11-27 12:43 ` [Tarantool-patches] [PATCH v2 2/2] bitset: replace zero-length array with flexible-array member Artem Starshov
2020-11-30 12:47   ` Aleksandr Lyapunov
2020-12-09  8:11   ` Leonid Vasiliev
2020-12-01 14:16 ` [Tarantool-patches] [PATCH v2 0/2] GCC 10 fix warnings Alexander V. Tikhonov
2020-12-02  0:27   ` Alexander V. Tikhonov
2020-12-16 11:47 ` Kirill Yukhin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox