Clang 3.3 findings and Illegal Shifts

Started by Jeffrey Waltonover 12 years ago3 messagesbugs
Jump to latest
#1Jeffrey Walton
noloader@gmail.com

Here are Clang 3.3 findings regarding illegal shifts. The code will be
subject to removal by the compiler and optimizer (and linker if LTO is
used).

The recipe used to produce the findings is below.

*****

$ /usr/local/bin/clang -v
clang version 3.3 (tags/RELEASE_33/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix

*****

make distclean

export CC=/usr/local/bin/clang
export CXX=/usr/local/bin/clang++
export CFLAGS="-g3 -fsanitize=undefined"
export CXXFLAGS="-g3 -fsanitize=undefined -fno-sanitize=vptr"

./configure

make

make check

*****

...
creating directory
/home/jwalton/Desktop/postgresql-9.3.1/src/test/regress/./tmp_check/data
... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
creating configuration files ... localtime.c:127:20: runtime error:
left shift of negative value -1
ok
creating template1 database in
/home/jwalton/postgresql-9.3.1/src/test/regress/./tmp_check/data/base/1
... localtime.c:127:20: runtime error: left shift of negative value -1
relmapper.c:670:2: runtime error: left shift of negative value -1
ok
initializing pg_authid ... localtime.c:127:20: runtime error: left
shift of negative value -1
ok
initializing dependencies ... localtime.c:127:20: runtime error: left
shift of negative value -1
ok
creating system views ... localtime.c:127:20: runtime error: left
shift of negative value -1
ok
loading system objects' descriptions ... localtime.c:127:20: runtime
error: left shift of negative value -1
ok
creating collations ... localtime.c:127:20: runtime error: left shift
of negative value -1
ok
creating conversions ... localtime.c:127:20: runtime error: left shift
of negative value -1
ok
creating dictionaries ... localtime.c:127:20: runtime error: left
shift of negative value -1
ok
setting privileges on built-in objects ... localtime.c:127:20: runtime
error: left shift of negative value -1
ok
creating information schema ... localtime.c:127:20: runtime error:
left shift of negative value -1
localtime.c:127:20: runtime error: left shift of negative value -1
ok
loading PL/pgSQL server-side language ... localtime.c:127:20: runtime
error: left shift of negative value -1
ok
vacuuming database template1 ... localtime.c:127:20: runtime error:
left shift of negative value -1
pg_lzcompress.c:601:5: runtime error: left shift of negative value -68
pg_lzcompress.c:601:5: runtime error: left shift of negative value -68
pg_lzcompress.c:385:16: runtime error: left shift of negative value -68
pg_lzcompress.c:615:4: runtime error: left shift of negative value -68
pg_lzcompress.c:385:16: runtime error: left shift of negative value -37
pg_lzcompress.c:615:4: runtime error: left shift of negative value -37
pg_lzcompress.c:385:16: runtime error: left shift of negative value -37
pg_lzcompress.c:615:4: runtime error: left shift of negative value -37
pg_lzcompress.c:601:5: runtime error: left shift of negative value -37
inval.c:524:39: runtime error: left shift of negative value -1
relmapper.c:670:2: runtime error: left shift of negative value -1
ok
copying template1 to template0 ... localtime.c:127:20: runtime error:
left shift of negative value -1
relmapper.c:670:2: runtime error: left shift of negative value -1
inval.c:524:39: runtime error: left shift of negative value -1
ok
copying template1 to postgres ... localtime.c:127:20: runtime error:
left shift of negative value -1
ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Sync to disk skipped.
The data directory might become corrupt if the operating system crashes.

Success. You can now start the database server using:
...

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#2Andres Freund
andres@anarazel.de
In reply to: Jeffrey Walton (#1)
Re: Clang 3.3 findings and Illegal Shifts

On 2013-11-12 19:58:31 -0500, Jeffrey Walton wrote:

Here are Clang 3.3 findings regarding illegal shifts. The code will be
subject to removal by the compiler and optimizer (and linker if LTO is
used).

/home/jwalton/postgresql-9.3.1/src/test/regress/./tmp_check/data/base/1
... localtime.c:127:20: runtime error: left shift of negative value -1

Those all seem to be runtime errors, so they aren't likely to be removed
by the compiler. That's not to say they shouldn't be looked at though.

Greetings,

Andres Freund

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#3Kevin Grittner
Kevin.Grittner@wicourts.gov
In reply to: Andres Freund (#2)
Re: Clang 3.3 findings and Illegal Shifts

Andres Freund <andres@2ndquadrant.com> wrote:

On 2013-11-12 19:58:31 -0500, Jeffrey Walton wrote:

Here are Clang 3.3 findings regarding illegal shifts. The code
will be subject to removal by the compiler and optimizer (and
linker if LTO is used).

Those all seem to be runtime errors, so they aren't likely to be
removed by the compiler. That's not to say they shouldn't be
looked at though.

Attached are the runtime errors I got from using the clang 3.4
sanitizer with make check-world.  I poked around some web search
results and found that according to the C99 spec, these seemed to
be flagging non-portable code.  I doubt that the issue impacts any
currently-supported platforms, which is why I set it aside until I
saw this thread; but it might some day affect the ability to
support some new platform.

These runtime tests can't be considered complete because the
sanitizer chose to crash things five times when it found things it
didn't like.  What it disliked was not immediately clear to me, but
I'll attach those, too.  Four of the five are identical for the
first 20 lines in the stack trace, with similarities for a few
lines past that.  Also attached, FWIW.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachments:

clang-sanitizer-runtime-error.txttext/plain; name=clang-sanitizer-runtime-error.txtDownload
clang-sanitizer-1.txttext/plain; name=clang-sanitizer-1.txtDownload
clang-sanitizer-4.txttext/plain; name=clang-sanitizer-4.txtDownload
clang-sanitizer-3.txttext/plain; name=clang-sanitizer-3.txtDownload
clang-sanitizer-2.txttext/plain; name=clang-sanitizer-2.txtDownload
clang-sanitizer-5.txttext/plain; name=clang-sanitizer-5.txtDownload