Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect mangling of __bf16 in template parameter with nested namespaces. #115521

Open
SagarMaheshwari99 opened this issue Nov 8, 2024 · 1 comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@SagarMaheshwari99
Copy link

namespace NS1 {

    namespace NS2 {
        struct NS2_struct1 {};
    }

    template<typename tpVal, typename tpVal1>
    class Class1 {};

    template<typename tpVal>
    using Name1 = Class1<tpVal, NS2::NS2_struct1>;
}

template <typename dtype>
void MyFunc(NS1::Name1<dtype>& input) {}

typedef __bf16 bfloat16;

struct bf16_struct {
    short a;
};

int main() {
    NS1::Class1<bfloat16, NS1::NS2::NS2_struct1> input;
    MyFunc<bfloat16>(input);

    NS1::Class1<bf16_struct, NS1::NS2::NS2_struct1> input1;
    MyFunc<bf16_struct>(input1);

    return 0;
}

For __bf16 case the mangling comes out to be -
_Z6MyFuncIu6__bf16EvRN3NS16Class1IT_NS0_3NS211NS2_struct1EEE

which demangled comes out to be -
void MyFunc<__bf16>(NS1::Class1<__bf16, __bf16::NS2::NS2_struct1>&)

which is incorrect, as __bf16 is treated as a namespace here.

For bf16_struct, right mangling is produced -
_Z6MyFuncI11bf16_structEvRN3NS16Class1IT_NS1_3NS211NS2_struct1EEE

and the demangling comes out to be -
void MyFunc<bf16_struct>(NS1::Class1<bf16_struct, NS1::NS2::NS2_struct1>&)

https://godbolt.org/z/dTWxYbqhM

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Nov 8, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 8, 2024

@llvm/issue-subscribers-clang-frontend

Author: Sagar Maheshwari (SagarMaheshwari99)

``` namespace NS1 {
namespace NS2 {
    struct NS2_struct1 {};
}

template&lt;typename tpVal, typename tpVal1&gt;
class Class1 {};

template&lt;typename tpVal&gt;
using Name1 = Class1&lt;tpVal, NS2::NS2_struct1&gt;;

}

template <typename dtype>
void MyFunc(NS1::Name1<dtype>& input) {}

typedef __bf16 bfloat16;

struct bf16_struct {
short a;
};

int main() {
NS1::Class1<bfloat16, NS1::NS2::NS2_struct1> input;
MyFunc<bfloat16>(input);

NS1::Class1&lt;bf16_struct, NS1::NS2::NS2_struct1&gt; input1;
MyFunc&lt;bf16_struct&gt;(input1);

return 0;

}


For __bf16 case the mangling comes out to be -
`_Z6MyFuncIu6__bf16EvRN3NS16Class1IT_NS0_3NS211NS2_struct1EEE`

which demangled comes out to be -
`void MyFunc&lt;__bf16&gt;(NS1::Class1&lt;__bf16, __bf16::NS2::NS2_struct1&gt;&amp;)`

which is incorrect, as __bf16 is treated as a namespace here.


For bf16_struct, right mangling is produced -
`_Z6MyFuncI11bf16_structEvRN3NS16Class1IT_NS1_3NS211NS2_struct1EEE`

and the demangling comes out to be -
`void MyFunc&lt;bf16_struct&gt;(NS1::Class1&lt;bf16_struct, NS1::NS2::NS2_struct1&gt;&amp;)`



https://godbolt.org/z/dTWxYbqhM



</details>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

3 participants