[llvm-bugs] [Bug 32679] New: [Windows]Clang Coverage attempts to mangle name of not fully instantiated class template function

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Apr 16 12:13:48 PDT 2017


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

            Bug ID: 32679
           Summary: [Windows]Clang Coverage attempts to mangle name of not
                    fully instantiated class template function
           Product: new-bugs
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: adamf88 at gmail.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 18293
  --> https://bugs.llvm.org/attachment.cgi?id=18293&action=edit
My patch to solve this issue, source code and build script

Clang Coverage reports an error when trying to mangle name of not fully
instantiated class template function on Windows.

>From the code below, Clang tries to create mangled name of the function "Max".

Sample code:
“
template <typename T, bool has_infinity>
struct RangeBase;

template<typename T>
struct RangeBase<T, true>
{
        static constexpr T Min()
        {
                return -1;
        }

        static constexpr T Max()
        {
                return -1;
        }
};

int main()
{
        //if uncommented then compiles properly
        //RangeBase<float, true>::Max();
        RangeBase<float, true>::Min();

        return 0;
} 
“

Compilation Command:

clang++ -cc1 -triple i686-pc-windows-msvc19.0.0 -emit-obj
-fprofile-instrument=clang -O0 -std=c++14 -fdelayed-template-parsing
-fcoverage-mapping -o "bug1.obj" bug1.cpp

Error message after compilation:

error: cannot mangle this template type parameter type yet
1>CL : error : cannot mangle this template type parameter type yet
1>bug1.cpp(12,2): error : cannot mangle this template type parameter type yet
1>        static constexpr T Max()
1>        ^~~~~~~~~~~~~~~~~~~~~~~~

It look like the problem starts in file ModuleBuilder.cpp in function
HandleInlineFunctionDefinition. 
This function calls AddDeferredUnusedCoverageMapping which adds function "Max"
to the DenseMap DeferredEmptyCoverageMappingDecls.
Later there is an attempt to mangle name of this partially instantiated
function.

I suppose name of this function shouldn’t be mangled. It shouldn't even be in
this Map.
I have created simple patch: bug1Patch.patch (in attachment). It should solve
this issue.

My simple Patch (also in attachment):

Index: ModuleBuilder.cpp
===================================================================
--- ModuleBuilder.cpp   (revision 300404)
+++ ModuleBuilder.cpp   (working copy)
@@ -197,7 +197,9 @@
       // Provide some coverage mapping even for methods that aren't emitted.
       // Don't do this for templated classes though, as they may not be
       // instantiable.
-      if (!MD->getParent()->getDescribedClassTemplate())
+      const CXXRecordDecl *RD = MD->getParent();
+      if (!RD->getDescribedClassTemplate() &&
+          !isa<ClassTemplatePartialSpecializationDecl>(RD))
         Builder->AddDeferredUnusedCoverageMapping(MD);
     }

-- 
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/20170416/01f9d31c/attachment.html>


More information about the llvm-bugs mailing list