[llvm-bugs] [Bug 37398] New: Incorrect std::type_info comparison and hash_code for pointer to incomplete type

via llvm-bugs llvm-bugs at lists.llvm.org
Wed May 9 12:56:31 PDT 2018


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

            Bug ID: 37398
           Summary: Incorrect std::type_info comparison and hash_code for
                    pointer to incomplete type
           Product: libc++
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: vsapsai at apple.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

Created attachment 20275
  --> https://bugs.llvm.org/attachment.cgi?id=20275&action=edit
Repro that gets std::type_info in different translation units and compares
them.

Steps to reproduce:
1. With typeid get std::type_info for a pointer to incomplete type in one
translation unit.
2. Get std::type_info for the same type in different translation unit.
3. Compare obtained type_info.
4. Compare hashes of obtained type_info.

Small repro case is attached.

Actual result:
Types are considered to be different, hash codes are different.
std::type_info::name() are equal by value, char* pointers are different.

Expected result:
Types should be equal, hash codes should be equal.

Comments:
In this case clang emits type info with internal linkage [1] which is correct
according to my understanding of Itanium C++ ABI. Also ABI documentation [2]
tells

> After linking and loading, only one std::type_info structure is accessible
> via the external name defined by this ABI for any particular complete type
> symbol (see Vague Linkage). Therefore, except for direct or indirect pointers
> to incomplete types, the equality and inequality operators can be written as
> address comparisons when operating on those type_info objects: two type_info
> structures describe the same type if and only if they are the same structure
> (at the same address). However, in the case of pointer types, directly or
> indirectly pointing to incomplete class types, a more complex comparison is
> required, described below with the RTTI layout of pointer types.

So to me it looks like libc++ bug.

[1]
https://github.com/llvm-mirror/clang/blob/6a37651bb30339e60ea617d510b4703bcd2e89e8/lib/CodeGen/ItaniumCXXABI.cpp#L3013-L3023
[2] http://refspecs.linuxbase.org/cxxabi-1.83.html#rtti

-- 
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/20180509/da7f42b3/attachment.html>


More information about the llvm-bugs mailing list