incompatible pointer type

From: Robert Young <yayooo(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: incompatible pointer type
Date: 2011-10-18 10:03:39
Message-ID: CAJjz_NhLdKSchC=nFFFUCfgQ-C1KG9W-TG3vX1JmMUGx2pGETA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Platform:
OpenBSD 4.9 GENERIC.MP#819 amd64 Intel(R) Xeon(R) CPU E5620 @ 2.40GHz

Error:
gmake[4]: Entering directory `/tmp/pgxc/git/src/pl/plpgsql/src'
/usr/bin/bison -d -o pl_gram.c gram.y
gcc -DPGXC -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Wendif-labels -Wformat-security
-fno-strict-aliasing -fwrapv -fpic -DPIC -I. -I.
-I../../../../src/include -c -o pl_gram.o pl_gram.c
gram.y: In function 'plpgsql_yyparse':
gram.y:875: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:878: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:1229: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:1516: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:1521: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:1562: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:1568: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:1574: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:1580: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:1586: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:1592: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:1636: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:1796: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:1800: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:1807: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y: In function 'tok_is_keyword':
gram.y:2197: error: dereferencing pointer to incomplete type
gram.y:2197: error: dereferencing pointer to incomplete type
gram.y:2198: error: dereferencing pointer to incomplete type
gram.y: In function 'read_datatype':
gram.y:2419: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:2426: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:2443: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:2450: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y: In function 'read_fetch_direction':
gram.y:2624: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:2629: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:2634: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:2639: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:2645: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:2654: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:2663: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:2669: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:2674: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y: In function 'read_raise_options':
gram.y:3370: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:3373: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:3376: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gram.y:3379: warning: passing argument 2 of 'tok_is_keyword' from
incompatible pointer type
gmake[4]: *** [pl_gram.o] Error 1
gmake[4]: Leaving directory `/tmp/pgxc/git/src/pl/plpgsql/src'

CAUSE:
let's inspect an error sample:
wrong1.c :
struct bar;
void foo(struct bar *p)
{}
typedef struct
{int a;
} bar ;
bar u;
int main()
{foo(&u);
return(0);
}

# gcc wrong1.c
wrong1.c: In function 'main':
wrong1.c:9: warning: passing argument 1 of 'foo' from incompatible pointer type

BECAUSE: The former "bar" and the latter "bar" are NOT RELEVANT.
If we rename the former "bar" to "bar_anthoer" ,the compiler would
give the same reply.
wrong2.c :
struct bar_another;
void foo(struct bar_another *p)
{}
typedef struct
{int a;
} bar ;
bar u;
int main()
{foo(&u);
return(0);
}

# gcc wrong2.c
wrong2.c: In function 'main':
wrong2.c:9: warning: passing argument 1 of 'foo' from incompatible pointer type

let's fix it.
right.c :
typedef struct
{int a;
} bar ;
void foo(bar *p)
{}
bar u;
int main()
{foo(&u);
return(0);
}

FIX:
1.delete "YYSTYPE" forward-declaration
2.move "tok_is_keyword" forward-declaration behind "YYSTYPE" definition
3.delete keyword "union" in function arguments.
OK.these will eliminate all the warnings.

diff --git a/src/pl/plpgsql/src/gram.y b/src/pl/plpgsql/src/gram.y
index 4e2b705..b632a76 100644
--- a/src/pl/plpgsql/src/gram.y
+++ b/src/pl/plpgsql/src/gram.y
@@ -53,10 +53,6 @@ typedef struct

#define parser_errposition(pos) plpgsql_scanner_errposition(pos)

-union YYSTYPE; /* need forward
reference for tok_is_keyword */
-
-static bool tok_is_keyword(int token, union YYSTYPE *lval,
-
int kw_token, const char *kw_str);
static void word_is_not_variable(PLword *word, int
location);
static void cword_is_not_variable(PLcword *cword,
int location);
static void current_token_is_not_variable(int tok);
@@ -318,6 +314,10 @@ static List
*read_raise_options(void);
%token <keyword> K_WHEN
%token <keyword> K_WHILE

+%{
+static bool tok_is_keyword(int token, YYSTYPE *lval,
+
int kw_token, const char *kw_str);
+%}
%%

pl_function : comp_options pl_block opt_semi
@@ -2179,7 +2179,7 @@ unreserved_keyword :
* Hence, this kluge.
*/
static bool
-tok_is_keyword(int token, union YYSTYPE *lval,
+tok_is_keyword(int token, YYSTYPE *lval,
int kw_token, const char *kw_str)
{
if (token == kw_token)

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Robert Haas 2011-10-18 13:32:24 Re: [v9.2] make_greater_string() does not return a string in some cases
Previous Message Laerson keler 2011-10-18 09:16:53 Re: BUG #6258: Lock Sequence