[llvm] r257284 - [ADT] Add an abstraction for embedding an integer within a pointer-like

Ismail Donmez via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 10 05:05:37 PST 2016


Hi,

On Sun, Jan 10, 2016 at 11:40 AM, Chandler Carruth via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: chandlerc
> Date: Sun Jan 10 03:40:13 2016
> New Revision: 257284
>
> URL: http://llvm.org/viewvc/llvm-project?rev=257284&view=rev
> Log:
> [ADT] Add an abstraction for embedding an integer within a pointer-like
> type.
>
> This makes it easy and safe to use a set of flags as one elmenet of
> a tagged union with pointers. There is quite a bit of code that has
> historically done this by casting arbitrary integers to "pointers" and
> assuming that this was safe and reliable. It is neither, and has started
> to rear its head by triggering safety asserts in various abstractions
> like PointerLikeTypeTraits when the integers chosen are invariably poor
> choices for *some* platform and *some* situation. Not to mention the
> (hopefully unlikely) prospect of one of these integers actually getting
> allocated!
>
> With this, it will be straightforward to build type safe abstractions
> like this without being error prone. The abstraction itself is also
> remarkably simple thanks to the implicit conversion.
>
> This use case and pattern was also independently created by the folks
> working on Swift, and they're going to incrementally add any missing
> functionality they find.
>
> Differential Revision: http://reviews.llvm.org/D15844
>
> Added:
>     llvm/trunk/include/llvm/ADT/PointerEmbeddedInt.h
>     llvm/trunk/unittests/ADT/PointerEmbeddedIntTest.cpp
> Modified:
>     llvm/trunk/unittests/ADT/CMakeLists.txt

VS2015 doesn't like it:

[2474/2645] Building CXX object
unittests\ADT\CMakeFiles\ADTTests.dir\PointerIntPairTest.cpp.obj
FAILED: C:\PROGRA~2\MICROS~1.0\VC\BIN\amd64\cl.exe   /nologo /TP
-DGTEST_HAS_RTTI=0 -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC
_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS
-D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE
_NO_WARNINGS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS
-D__STDC_LIMIT_MACROS -Iunittests\ADT -I..\unittests\ADT -Iinclud
e -I..\include -I..\utils\unittest\googletest\include /DWIN32
/D_WINDOWS   /W4 -wd4141 -wd4146 -wd4180 -wd4244 -wd4258 -wd4267
 -wd4291 -wd4345 -wd4351 -wd4355 -wd4456 -wd4457 -wd4458 -wd4459
-wd4503 -wd4624 -wd4722 -wd4800 -wd4100 -wd4127 -wd4512 -wd45
05 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703
-wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd
4324 -w14062 -we4238 /Zc:inline /Zc:sizedDealloc- /MT /O2 /Ob2
-UNDEBUG  /EHs-c- /GR- /showIncludes /Founittests\ADT\CMakeFi
les\ADTTests.dir\PointerEmbeddedIntTest.cpp.obj
/Fdunittests\ADT\CMakeFiles\ADTTests.dir\ /FS -c
..\unittests\ADT\PointerEmbed
dedIntTest.cpp
..\include\llvm/ADT/PointerEmbeddedInt.h(33): error C2327:
'llvm::PointerEmbeddedInt<IntT,Bits>::Value': is not a type name, s
tatic, or enumerator
..\include\llvm/ADT/PointerEmbeddedInt.h(64): note: see reference to
class template instantiation 'llvm::PointerEmbeddedInt<In
tT,Bits>' being compiled
..\include\llvm/ADT/PointerEmbeddedInt.h(33): error C2065: 'Value':
undeclared identifier
..\include\llvm/ADT/PointerEmbeddedInt.h(33): error C2327:
'llvm::PointerEmbeddedInt<int,8>::Value': is not a type name, stati
c, or enumerator
..\unittests\ADT\PointerEmbeddedIntTest.cpp(17): note: see reference
to class template instantiation 'llvm::PointerEmbeddedInt
<int,8>' being compiled
..\include\llvm/ADT/PointerEmbeddedInt.h(34): error C2338: Cannot
embed more bits than we have in a pointer!
..\include\llvm/ADT/PointerEmbeddedInt.h(39): error C2327:
'llvm::PointerEmbeddedInt<int,8>::Value': is not a type name, stati
c, or enumerator
..\include\llvm/ADT/PointerEmbeddedInt.h(39): error C2065: 'Value':
undeclared identifier


More information about the llvm-commits mailing list