[llvm-bugs] [Bug 46161] New: clang/libclang crashes on parsing (std >= c++14) on all versions (recursion bug)

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jun 1 09:44:06 PDT 2020


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

            Bug ID: 46161
           Summary: clang/libclang crashes on parsing (std >= c++14) on
                    all versions (recursion bug)
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++14
          Assignee: unassignedclangbugs at nondot.org
          Reporter: xutaxkamay at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

Created attachment 23562
  --> https://bugs.llvm.org/attachment.cgi?id=23562&action=edit
Code source that causes the crash.

Hello dear LLVM/clang developers.

I've discovered a crash with clang that seem to happen on every versions when
std >= 14.
I have tested with clang version 8,9,10,11, it has the same problem everywhere.

My thoughts are that it seems to happen when one template function have the
same name, same arguments and template arguments, when using template
parameters packs as last template argument.

When clang tries to parse it, it is processing the template function1 in
compile-time for creating the function1 that will be used next for compiling,
and clang resolves it recursively by calling the wrong template function1
instead of calling template function2.

template function1 and template function2 have the same function name (to avoid
confusion) of course.

Results:

....

1.      main.cpp:24:29: current parser token ')'
2.      main.cpp:23:1: parsing function body 'main'
3.      main.cpp:23:1: in compound statement ('{}')
4.      ./types.h:73:27: instantiating function definition 'XLib::CVFunc<0,
void (*)()>'
5.      ./types.h:61:27: instantiating function definition 'XLib::VFunc<0, void
(*)()>'
6.      ./types.h:61:27: instantiating function definition 'XLib::VFunc<0, void
(*(*)())()>'
7.      ./types.h:61:27: instantiating function definition 'XLib::VFunc<0, void
(*(*(*)())())()>'
8.      ./types.h:61:27: instantiating function definition 'XLib::VFunc<0, void
(*(*(*(*)())())())()>'

....


I've attached an example of source code inside the attachments so you can debug
it yourself because it is easily reproducible, in hope it could help.

Commands used:
clang-8 -std=c++14 -o main main.cpp  
clang-9 -std=c++14 -o main main.cpp  
clang-11 -std=c++14 -o main main.cpp  
clang-11 -std=c++14 -o main main.cpp

....

I would be glad that it could be fixed, even if it's my coding style that isn't
very pleasant...

Thank you!

-- 
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/20200601/76789616/attachment.html>


More information about the llvm-bugs mailing list