Bug#837963: clang-4.0: bogus valgrind warning from push_back() on std::string

Olly Betts olly at survex.com
Thu Sep 15 23:02:26 UTC 2016

Package: clang-4.0
Version: 1:4.0~svn279916-1
Severity: normal

If I compile this reduced testcase with clang++-4.0 and run it under
valgrind, I get a bogus warning from the second push_back().  If I
compile with other versions of clang++ or g++ from Debian I don't
get this warning:

$ cat unittest.cc 
#include <exception>
#include <iostream>
#include <string>

using namespace std;

typedef void (*func)();

struct S {
    static void run(func t) {
	try {
	} catch (const std::exception&) {
	    cout << "std::exception" << endl;

static void f() {
    string s;
    cout << s << endl;

int main() {
$ clang++-4.0 -g -O2 -o unittest unittest.cc && valgrind ./unittest 
==15131== Memcheck, a memory error detector
==15131== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==15131== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright info
==15131== Command: ./unittest
==15131== Conditional jump or move depends on uninitialised value(s)
==15131==    at 0x400C7F: push_back (basic_string.h:1167)
==15131==    by 0x400C7F: f() (unittest.cc:22)
==15131==    by 0x400CF2: S::run(void (*)()) (unittest.cc:12)
==15131==    by 0x400C4A: main (unittest.cc:26)
==15131== HEAP SUMMARY:
==15131==     in use at exit: 0 bytes in 0 blocks
==15131==   total heap usage: 1 allocs, 1 frees, 72,704 bytes allocated
==15131== All heap blocks were freed -- no leaks are possible
==15131== For counts of detected and suppressed errors, rerun with: -v
==15131== Use --track-origins=yes to see where uninitialised values come from
==15131== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

The resulting value of s seems to be correct, so it's not entirely clear
to me if the issue is with the generated code, or if this is actually a
valgrind problem, but as it is specific to this compiler version it
seems there's at least some change in the compiler which is triggering


-- System Information:
Debian Release: stretch/sid
  APT prefers unstable-debug
  APT policy: (500, 'unstable-debug'), (500, 'unstable'), (500, 'stable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.6.0-1-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_NZ.UTF-8, LC_CTYPE=en_NZ.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages clang-4.0 depends on:
ii  binutils                 2.27-8
ii  libc6                    2.24-2
ii  libc6-dev                2.24-2
ii  libclang-common-4.0-dev  1:4.0~svn279916-1
ii  libclang1-4.0            1:4.0~svn279916-1
ii  libgcc-6-dev             6.2.0-3
ii  libgcc1                  1:6.2.0-3
ii  libjsoncpp1              1.7.4-3
ii  libllvm4.0               1:4.0~svn279916-1
ii  libobjc-6-dev            6.2.0-3
ii  libstdc++-6-dev          6.2.0-3
ii  libstdc++6               6.2.0-3

Versions of packages clang-4.0 recommends:
ii  llvm-4.0-dev  1:4.0~svn279916-1
ii  python        2.7.11-2

Versions of packages clang-4.0 suggests:
pn  clang-4.0-doc  <none>
pn  gnustep        <none>
pn  gnustep-devel  <none>

-- no debconf information
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/pkg-llvm-team/attachments/20160916/13dc4224/attachment.sig>

More information about the Pkg-llvm-team mailing list