[LLVMbugs] [Bug 23833] New: If the contents of a nullptr_t are modified through type-punned union, conversions from that nullptr_t to bool don't behave the same as conversion from nullptr to bool

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jun 12 11:39:11 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=23833

            Bug ID: 23833
           Summary: If the contents of a nullptr_t are modified through
                    type-punned union, conversions from that nullptr_t to
                    bool don't behave the same as conversion from nullptr
                    to bool
           Product: clang
           Version: 3.6
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: andrey.vul at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

According to [conv.ptr]/1, conversion from nullptr_t to bool is equivalent to
conversion from null pointer to bool.
The Standard does not specify whether conversion should happen from internal
state initialized at construction or from some pseudo-function `constexpr
nullpt_t::operator bool() const { return false; }`.

The test case uses a union to mutate the internals of a nullptr_t and then
checks if nullptr_t still converts correctly to bool, as if it were an
invariant of the type. In effect, the value of the nullptr_t need not be
accessed at cast since it's intended to decay to null pointer constant when
used as a prvalue.
But the value is accessed, causing the test case to fail.

### SOURCE: cat a.cc
#include <cassert>
union {
int x;
nullptr_t y;
} a = {37};

int main() {
assert(!static_cast<bool>(a.y));
}

## INVOCATION: clang++ -std=c++11 -v a.cc
clang version 3.6.1 (tags/RELEASE_361/final)
Target: powerpc64le-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/powerpc64le-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/powerpc64le-linux-gnu/4.9.1
Selected GCC installation: /usr/lib/gcc/powerpc64le-linux-gnu/4.9
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/gsa/tlbgsa-h1/09/andreyv/clang/bin/clang-3.6" -cc1 -triple
powerpc64le-unknown-linux-gnu -emit-obj -mrelax-all -disable-free
-main-file-name a.cc -mrelocation-model static -mthread-model posix
-mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases
-fuse-init-array -target-cpu ppc64le -target-abi elfv2 -v -dwarf-column-info
-resource-dir /gsa/tlbgsa-h1/09/andreyv/clang/bin/../lib/clang/3.6.1
-internal-isystem
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../../include/c++/4.9
-internal-isystem
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../../include/powerpc64le-linux-gnu/c++/4.9
-internal-isystem
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../../include/powerpc64le-linux-gnu/c++/4.9
-internal-isystem
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../../include/c++/4.9/backward
-internal-isystem /usr/local/include -internal-isystem
/gsa/tlbgsa-h1/09/andreyv/clang/bin/../lib/clang/3.6.1/include
-internal-externc-isystem /usr/include/powerpc64le-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include
-std=c++11 -fdeprecated-macro -fdebug-compilation-dir /tmp -ferror-limit 19
-fmessage-length 129 -mstackrealign -fno-signed-char -fobjc-runtime=gcc
-fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o
/tmp/a-98ec2a.o -x c++ a.cc
clang -cc1 version 3.6.1 based upon LLVM 3.6.1 default target
powerpc64le-unknown-linux-gnu
ignoring nonexistent directory "/include"
ignoring duplicate directory
"/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../../include/powerpc64le-linux-gnu/c++/4.9"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../../include/c++/4.9

/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../../include/powerpc64le-linux-gnu/c++/4.9
 /usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../../include/c++/4.9/backward
 /usr/local/include
 /gsa/tlbgsa-h1/09/andreyv/clang/bin/../lib/clang/3.6.1/include
 /usr/include/powerpc64le-linux-gnu
 /usr/include
End of search list.
 "/usr/bin/ld" --eh-frame-hdr -m elf64lppc -dynamic-linker /lib64/ld64.so.2 -o
a.out
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../powerpc64le-linux-gnu/crt1.o
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../powerpc64le-linux-gnu/crti.o
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/crtbegin.o
-L/usr/lib/gcc/powerpc64le-linux-gnu/4.9
-L/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../powerpc64le-linux-gnu
-L/lib/powerpc64le-linux-gnu -L/lib/../lib64 -L/usr/lib/powerpc64le-linux-gnu
-L/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../..
-L/gsa/tlbgsa-h1/09/andreyv/clang/bin/../lib -L/lib -L/usr/lib /tmp/a-98ec2a.o
-lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/crtend.o
/usr/lib/gcc/powerpc64le-linux-gnu/4.9/../../../powerpc64le-linux-gnu/crtn.o

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150612/1e227214/attachment.html>


More information about the llvm-bugs mailing list