Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

crash when substituting dependent default argument in partial specialization #12476

Open Quuxplusone opened 12 years ago

Quuxplusone commented 12 years ago
Bugzilla Link PR12362
Status NEW
Importance P normal
Reported by Tobi (freunddeslichts@web.de)
Reported on 2012-03-26 17:17:26 -0700
Last modified on 2012-04-08 16:39:52 -0700
Version trunk
Hardware PC Linux
CC dgregor@apple.com, fang@csl.cornell.edu, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Clang++ crashes on the folloging code

template <int N, typename T>
struct point {
    T data[N];
};

template <int K, typename T>
struct recursion;

template <typename T>
struct recursion<0, T> {

    template <typename T2 = T>
    using pt = point<3, T2>;

    static int test(const pt<>&)
    {
        return 0;
    }
};

int main(void)
{
    return 0;
}

output is as follows

~/Dokumente/clang/release2/Release/bin/clang++  -std=c++0x bug.cpp -Wall
0  clang 0x0977314b
Stack dump:
0.  Program arguments: /home/tobi/Dokumente/clang/release2/Release/bin/clang -
cc1 -triple i386-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-
verifier -main-file-name bug.cpp -mrelocation-model static -mdisable-fp-elim -
masm-verbose -mconstructor-aliases -target-cpu pentium4 -momit-leaf-frame-
pointer -resource-dir
/home/tobi/Dokumente/clang/release2/Release/bin/../lib/clang/3.1 -fmodule-cache-
path /var/tmp/clang-module-cache -internal-isystem /usr/lib/gcc/i686-linux-
gnu/4.7/../../../../include/c++/4.7 -internal-isystem /usr/lib/gcc/i686-linux-
gnu/4.7/../../../../include/c++/4.7/i686-linux-gnu -internal-isystem
/usr/lib/gcc/i686-linux-gnu/4.7/../../../../include/c++/4.7/backward -internal-
isystem /usr/local/include -internal-isystem
/home/tobi/Dokumente/clang/release2/Release/bin/../lib/clang/3.1/include -
internal-externc-isystem /usr/include/i386-linux-gnu -internal-externc-isystem
/include -internal-externc-isystem /usr/include -Wall -std=c++0x -fdeprecated-
macro -fdebug-compilation-dir /home/tobi/Dokumente/bug -ferror-limit 19 -
fmessage-length 178 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc -fobjc-
runtime-has-weak -fobjc-fragile-abi -fcxx-exceptions -fexceptions -fdiagnostics-
show-option -fcolor-diagnostics -o /tmp/bug-i6NxPy.o -x c++ bug.cpp
1.  bug.cpp:21:24: at annotation token
2.  bug.cpp:15:1: parsing struct/union/class body 'recursion'
clang: error: unable to execute command: Segmentation fault (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see
invocation)
clang: note: diagnostic msg: Please submit a bug report to
http://llvm.org/bugs/ and include command line arguments and all diagnostic
information.
clang: note: diagnostic msg: Preprocessed source(s) and associated run
script(s) are located at:
clang: note: diagnostic msg: /tmp/bug-3L1HIS.ii
clang: note: diagnostic msg: /tmp/bug-3L1HIS.sh
Quuxplusone commented 12 years ago
The alias template is a red herring. The crash can be seen with:

    template <typename T2 = T>
    struct pt;
    //using pt = point<3, T2>;

The problem is that when we process

    static int test(const pt<>&)

we try to fill in the default arguments, and in so doing, call SubstType on the
'T' in the default argument (SemaTemplate.cpp:2496), which is template-
parameter-0-0. However, the template arguments for level 0 are <(int)0,
template-parameter-0-0>, so substitution finds '0', and asserts because it's
not a type.