Re: Has anyone used CLANG yet? - Mailing list pgsql-hackers

From A.M.
Subject Re: Has anyone used CLANG yet?
Date
Msg-id F6D8F5F8-B57B-4A4D-ABC8-C2719B9B83AD@themactionfaction.com
Whole thread Raw
In response to Has anyone used CLANG yet?  (Chris Browne <cbbrowne@acm.org>)
List pgsql-hackers
On Dec 9, 2009, at 4:23 PM, Chris Browne wrote:

> This is a C front end for the LLVM compiler...  I noticed that it
> entered Debian/Unstable today:
>
>  http://packages.debian.org/sid/main/clang
>
> I thought it would be interesting to see if PostgreSQL compiles with
> this, as an alternative compiler that should presumably become more and
> more available on Linux et al.  (And I suppose that the randomly
> selected .sig is supremely apropos!)
>
> configure blows up here at the following:
>
> conftest.c:75:28: error: invalid token after top level declarator
> extern unsigned int PASCAL accept (unsigned int, void *, void *);
>
> I suspect there's something about PASCAL that's a problem, as clang is
> nominally supposed to be a C compiler ;-).
>
> I haven't looked deeper, so haven't the remotest idea how deep the issue
> lies.
>
> At any rate, I should poke at this further soon, but if it seems
> interesting to others, well, CLANG is now an easy install on some number
> of systems!

Clang works for me on MacOS 10.6.2:/Developer/usr/bin/clang --version
clang version 1.0.1 (http://llvm.org/svn/llvm-project/cfe/tags/Apple/clang-24 exported)
Target: x86_64-apple-darwin10

CC="/Developer/usr/bin/clang" ./configure --prefix=/Users/agentm/pgsql841/

make -j 8

/Users/agentm/pgsql841/initdb -E UTF8 ../data

./pg_ctl -D ../data/ start
server starting
RD07:bin agentm$ LOG:  database system was shut down at 2009-12-09 17:01:51 EST
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started

/Users/agentm/pgsql841/psql postgres
psql (8.4.1)
Type "help" for help.

postgres=# select 1;?column?
----------       1
(1 row)


I do see lots of warnings regarding unsupported compiler flags:

clang: warning: argument unused during compilation: '-no-cpp-precomp'
clang: warning: argument unused during compilation: '-O2'
clang: warning: argument unused during compilation: '-Wall'
clang: warning: argument unused during compilation: '-Wmissing-prototypes'
clang: warning: argument unused during compilation: '-Wpointer-arith'
clang: warning: argument unused during compilation: '-Wdeclaration-after-statement'
clang: warning: argument unused during compilation: '-Wendif-labels'
clang: warning: argument unused during compilation: '-fno-strict-aliasing'
clang: warning: argument unused during compilation: '-fwrapv'

and some code-based warnings:
print.c:1105:24: warning: field width should have type 'int', but argument has type 'unsigned int' [-Wformat]
                   fprintf(fout, "%-s%*s", hlineptr[line_count].ptr,                                                  ^ 

pl_exec.c:3529:6: warning: expression result unused [-Wunused-value]
ItemPointerSetInvalid(&(tmptup.t_self));                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
../../../../src/include/storage/itemptr.h:134:2: note: instantiated from:       BlockIdSet(&((pointer)->ip_blkid),
InvalidBlockNumber),\       ^ 
../../../../src/include/storage/block.h:86:2: note: instantiated from:       AssertMacro(PointerIsValid(blockId)), \
  ^ 
../../../../src/include/postgres.h:675:39: note: instantiated from:
#define AssertMacro(condition)  ((void)true)                                      ^
../../../../src/include/c.h:185:15: note: instantiated from:
#define true    ((bool) 1)

You are probably running configure with gcc, no?

FYI:
with clang: time make (not -j 8)
real    1m46.511s
user    1m26.295s
sys    0m14.639s

with gcc: time make
real    2m41.934s
user    2m20.778s
sys    0m17.441s

du -h pgsql841gcc/bin/*52K    pgsql841gcc/bin/clusterdb52K    pgsql841gcc/bin/createdb60K
pgsql841gcc/bin/createlang52K   pgsql841gcc/bin/createuser52K    pgsql841gcc/bin/dropdb60K
pgsql841gcc/bin/droplang52K   pgsql841gcc/bin/dropuser 
616K    pgsql841gcc/bin/ecpg72K    pgsql841gcc/bin/initdb32K    pgsql841gcc/bin/pg_config28K
pgsql841gcc/bin/pg_controldata36K   pgsql841gcc/bin/pg_ctl 
280K    pgsql841gcc/bin/pg_dump68K    pgsql841gcc/bin/pg_dumpall36K    pgsql841gcc/bin/pg_resetxlog
128K    pgsql841gcc/bin/pg_restore
4.6M    pgsql841gcc/bin/postgres
4.0K    pgsql841gcc/bin/postmaster
340K    pgsql841gcc/bin/psql52K    pgsql841gcc/bin/reindexdb32K    pgsql841gcc/bin/vacuumdb

du -h pgsql841/bin/* (clang build)52K    pgsql841/bin/clusterdb52K    pgsql841/bin/createdb60K
pgsql841/bin/createlang52K   pgsql841/bin/createuser48K    pgsql841/bin/dropdb60K    pgsql841/bin/droplang48K
pgsql841/bin/dropuser
612K    pgsql841/bin/ecpg72K    pgsql841/bin/initdb28K    pgsql841/bin/pg_config28K    pgsql841/bin/pg_controldata36K
pgsql841/bin/pg_ctl 
272K    pgsql841/bin/pg_dump68K    pgsql841/bin/pg_dumpall36K    pgsql841/bin/pg_resetxlog
124K    pgsql841/bin/pg_restore
4.5M    pgsql841/bin/postgres
4.0K    pgsql841/bin/postmaster
344K    pgsql841/bin/psql52K    pgsql841/bin/reindexdb32K    pgsql841/bin/vacuumdb

Cheers,
M






pgsql-hackers by date:

Previous
From: Greg Smith
Date:
Subject: Re: Has anyone used CLANG yet?
Next
From: Bruce Momjian
Date:
Subject: Re: Adding support for SE-Linux security