llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-cl] ICE instantiating partial specialization of variable template with /Zi

Open CaseyCarter opened this issue 7 years ago • 16 comments

Bugzilla Link 41677
Resolution FIXED
Resolved on May 28, 2019 11:21
Version 8.0
OS Windows NT
Attachments Repro files (.cpp & .sh)
CC @DougGregor,@ormris,@merlynomsft,@Neumann-A,@zygoloid,@rnk,@wjristow
Fixed by commit(s) r359809

Extended Description

Compiling this well-formed program:

template<class, class> constexpr bool is_same_v = false;
template<class T> constexpr bool is_same_v<T, T> = true;

struct codecvt {
#ifndef WORKAROUND
    virtual bool do_always_noconv() const {
        return is_same_v<char, char>;
    }
#else
    static constexpr bool foo = is_same_v<char, char>;
    virtual bool do_always_noconv() const {
        return foo;
    }
#endif
};

int main() {
    (void) codecvt{};
}

with "clang-cl /Zi" outputs:

C:\Users\cacarter\Downloads>clang-cl /Zi repro.cpp
0x00007FF71A5485A0 (0x000001B2E03494F8 0x000001B2E02ED650 0x00007E9B1AC874D6 0x000001B2E037A460)
0x00007FF71BF495C9 (0x0000000000000000 0x0000000000000000 0x000001B2E02EE310 0x000001B2E027F618)
0x00007FF71A0D4786 (0x000001B2E01302A8 0x00007FF9B449C44F 0x0000000000000020 0x000001B2E0130CC0)
0x00007FF71A168CF3 (0x000001B2E0230000 0x00007FF9B449B9A7 0x000001B2E0130000 0x000001B200000000)
0x00007FF71A74185F (0x000000297E189B01 0x000000297E18A840 0x00007E9B1AC87956 0x000001B2E037CE90)
0x00007FF71A742116 (0x0000000000000000 0xFFFFFFFFFFFFFFFF 0x0000000000000000 0xFFFFFFFFFFFFFFFF)
0x00007FF71A74EC94 (0x0000000000000000 0x000000297E18A840 0x000001B2E0349CB0 0x00007FF71A74D02E)
0x00007FF71A88CEF9 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x00007FF71A0E50B6)
0x00007FF71A9A1CAD (0x000001B2E02B8A80 0x000001B2E0130000 0x000001B2E01302AC 0x00007FF71A6CD59F)
0x00007FF71A9A9104 (0x0000000000000000 0x000001B2E03799DA 0x000001B2E03799D8 0x00007FF71A0D4981)
0x00007FF71A996ECE (0x0000000000000000 0x000001B2E02B7748 0x0000000000000000 0x00007FF71A143588)
0x00007FF71A94920A (0x000001B2E0349BA1 0x0000000000000008 0x00000000000000AF 0x00007FF71BCAAE46)
0x00007FF71A9460B1 (0x000001B2E0349D28 0x000001B200000000 0x0000000000000006 0x00007FF9B449C44F)
0x00007FF71A94EDC5 (0x000001B2E0349D28 0x00007FF71A8B4742 0x000001B2E0349D28 0x00000000000000AF)
0x00007FF71A874D7E (0x00007E9B1AC84466 0x000001B2E0349D28 0x00000000000000AF 0x000001B2E02AE620)
0x00007FF71A8756A9 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000)
0x00007FF71A703BBD (0x00000000E02B6B01 0x000001B2E0349D28 0x000001B2E02AE620 0x000001B2E0281D70)
0x00007FF71A6FDA60 (0x000000297E18BFA0 0x000001B2E029C5F0 0x000001B2E0281C00 0x00007FF71A6FD850)
0x00007FF71A6F5390 (0x000001B2E02B1835 0x000000297E18C090 0x000001B2E02B1836 0x000000297E18BF88)
0x00007FF71A6F53B8 (0x000001B2E0358B08 0x000001B2E0321030 0x000001B40000018F 0x0000000000000008)
0x00007FF71A6F4521 (0x00007E9B1AC82136 0x000000297E18D7A8 0x00007E9B1AC83776 0x000000297E18D7A8)
0x00007FF71C11FF65 (0x0000000000000000 0x00007FF71C120295 0x00007E9B1AC82166 0x000000297E18D7A8)
0x00007FF71C11E1E4 (0x000001B2E025E6B0 0x00007FF71AB378AA 0x0000000000000009 0x000001B200000013)
0x00007FF71B5742B3 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x000001B2E0238B60)
0x00007FF71AB76B3D (0x00000000000000C0 0x0000002DE02B3ED0 0x000001B2E0238B60 0x000001B2E027B740)
0x00007FF71AB3A897 (0x000000297E18DC01 0x0000000000000000 0x0000000000000000 0x0000000000000049)
0x00007FF71ABC80A8 (0x000001B2E028A1B0 0x0000000000000001 0x0000000000000047 0x000001B2E0230000)
0x00007FF719096BBC (0x00000000FD0000FD 0x00000000000000FD 0x0000000002000002 0x00000000000006B0)
0x00007FF7190941D7 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000)
0x00007FF71C1247B0 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000)
0x00007FF9B3BD7BD4 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000), BaseThreadInitThunk() + 0x14 bytes(s)
0x00007FF9B44CCE71 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000), RtlUserThreadStart() + 0x21 bytes(s)
clang-cl: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: c:\Program Files\LLVM\bin
clang-cl: note: diagnostic msg: PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
clang-cl: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-cl: note: diagnostic msg: C:\Users\cacarter\AppData\Local\Temp\repro-687e9c.cpp
clang-cl: note: diagnostic msg: C:\Users\cacarter\AppData\Local\Temp\repro-687e9c.sh
clang-cl: note: diagnostic msg:

********************

Compiling with "WORKAROUND" defined succeeds.

CaseyCarter avatar Apr 30 '19 22:04 CaseyCarter

mentioned in issue llvm/llvm-bugzilla-archive#42015

DimitryAndric avatar Nov 27 '21 02:11 DimitryAndric

mentioned in issue llvm/llvm-bugzilla-archive#42011

rnk avatar Nov 27 '21 02:11 rnk

mentioned in issue llvm/llvm-bugzilla-archive#42005

rnk avatar Nov 27 '21 02:11 rnk

mentioned in issue llvm/llvm-bugzilla-archive#41985

rnk avatar Nov 27 '21 02:11 rnk

*** Bug llvm/llvm-bugzilla-archive#41985 has been marked as a duplicate of this bug. ***

rnk avatar May 28 '19 18:05 rnk

*** Bug llvm/llvm-bugzilla-archive#42015 has been marked as a duplicate of this bug. ***

DimitryAndric avatar May 26 '19 11:05 DimitryAndric

*** Bug llvm/llvm-bugzilla-archive#42005 has been marked as a duplicate of this bug. ***

rnk avatar May 24 '19 20:05 rnk

Landed as r359809. Thanks for the reports!

rnk avatar May 02 '19 18:05 rnk

NVM. Thanks for the fix!

ormris avatar May 01 '19 23:05 ormris

Is this a duplicate of https://llvm.org/pr41642 ?

The dump in that PR includes "Generating code for declaration 'std::codecvt<char, char, _Mbstatet>::do_always_noconv'" so yes, they are certainly duplicates.

MSVC's std::codecvt primary template definition (yes, it's insane that we define the primary template but you can't ever take anything back from users) uses is_same_v in do_always_noconv. I updated our <type_traits> to use the variable templates rather than class templates as the source of truth in VS2019 for better throughput, and thereby exposed clang-cl to the above definition of is_same_v.

CaseyCarter avatar May 01 '19 23:05 CaseyCarter

*** Bug llvm/llvm-project#40987 has been marked as a duplicate of this bug. ***

rnk avatar May 01 '19 22:05 rnk

Hmm... I'll take a look at this.

I managed to put together what I think is the fix, and I'll dupe the other report against this one: https://reviews.llvm.org/D61408

rnk avatar May 01 '19 22:05 rnk

Hmm... I'll take a look at this.

ormris avatar May 01 '19 21:05 ormris

It looks like this new code added in r343707 is assuming that a partial specialization will have the same number of template parameters as there are template arguments, and that is not true.

rnk avatar May 01 '19 21:05 rnk

Is this a duplicate of https://llvm.org/pr41642 ?

rnk avatar May 01 '19 21:05 rnk

It appears the root cause is generating PDB info for a partial specialization of a variable template. Simplified repro:

#ifndef WORKAROUND
template<class, class> constexpr bool is_same_v = false;
template<class T> constexpr bool is_same_v<T, T> = true;
#else
template<class, class> struct is_same {
    static constexpr bool value = false;
};
template<class T> struct is_same<T, T> {
    static constexpr bool value = true;
};
template<class T, class U> constexpr bool is_same_v = is_same<T, T>::value;
#endif

int main() {
    (void) is_same_v<int, int>; // ICE
}

CaseyCarter avatar May 01 '19 01:05 CaseyCarter