This is an automated email from the ASF dual-hosted git repository.

yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit 5ccfc38409214f1bfb6021e6b65af011585a0707
Author: Yang, Ying-chao <yang.yingc...@qq.com>
AuthorDate: Wed Jul 5 09:38:20 2023 +0800

    fix compiler warning for gcc-12. (#15813)
    
    With gcc version 12.2.1 (Gentoo 12.2.1_p20230428-r1 p2), pgbench fails to
    compile with following error:
    commit 7cc8a58b865d96dad7e0b310ba72134de50f1152 introduced this
    flag in GPDB, and when using optimization level "O3" (as in GPDB) ,
    this flag can cause compilation failures with the gcc-12 compiler.
    
    ```
    In function 'coerceToInt',
        inlined from 'evalStandardFunc' at pgbench.c:2246:11:
    pgbench.c:1667:17: error: 'vargs[0].type' may be used uninitialized 
[-Werror=maybe-uninitialized]
     1667 |         if (pval->type == PGBT_INT)
          |             ~~~~^~~~~~
    pgbench.c: In function 'evalStandardFunc':
    pgbench.c:1875:22: note: 'vargs' declared here
     1875 |         PgBenchValue vargs[MAX_FARGS];
          |                      ^~~~~
    In function 'coerceToInt',
        inlined from 'evalStandardFunc' at pgbench.c:2246:11:
    pgbench.c:1669:32: error: 'vargs[0].u.ival' may be used uninitialized 
[-Werror=maybe-uninitialized]
     1669 |                 *ival = pval->u.ival;
          |                         ~~~~~~~^~~~~
    pgbench.c: In function 'evalStandardFunc':
    pgbench.c:1875:22: note: 'vargs' declared here
     1875 |         PgBenchValue vargs[MAX_FARGS];
          |                      ^~~~~
    In function 'coerceToInt',
        inlined from 'evalStandardFunc' at pgbench.c:2246:11:
    pgbench.c:1674:40: error: 'vargs[0].u.dval' may be used uninitialized 
[-Werror=maybe-uninitialized]
     1674 |                 double          dval = rint(pval->u.dval);
          |                                        ^~~~~~~~~~~~~~~~~~
    pgbench.c: In function 'evalStandardFunc':
    pgbench.c:1875:22: note: 'vargs' declared here
     1875 |         PgBenchValue vargs[MAX_FARGS];
          |                      ^~~~~
    ```
---
 src/bin/pgbench/pgbench.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 5080f33a3b..94451d369f 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -2076,6 +2076,9 @@ evalStandardFunc(CState *st,
        PgBenchExprLink *l = args;
        bool            has_null = false;
 
+       /* Some compiler (gcc-12) may raise warning about uninitialized 
variable */
+       memset(vargs, 0, sizeof(vargs));
+
        for (nargs = 0; nargs < MAX_FARGS && l != NULL; nargs++, l = l->next)
        {
                if (!evaluateExpr(st, l->expr, &vargs[nargs]))


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cloudberry.apache.org
For additional commands, e-mail: commits-h...@cloudberry.apache.org

Reply via email to