[cfe-dev] Using both OpenCL and GCC vectors

Yung, Douglas via cfe-dev cfe-dev at lists.llvm.org
Tue Feb 2 19:33:01 PST 2016


Hi,

In our testing, we discovered a regression in 3.8 when trying to use both OpenCL and GCC vectors in the same program. Consider the following code:

template <typename alpha>
static void foo() {}

void bar() {
  foo<float __attribute__((__vector_size__(16)))>();
  foo<float __attribute__((ext_vector_type(4)))>();
}

In 3.7, the code compiled without any errors, but in 3.8 it fails to compile. The problem is that clang considers GCC and OpenCL vectors to be unique types, but since they mangle identically, the compiler instantiates two versions of foo which are identical and emits an error:

repro.cpp:2:13: error: definition with same mangled name as another definition
static void foo() {}
            ^
repro4.cpp:2:13: note: previous definition is here
1 error generated.

The error is unfortunately not very helpful and was filed as PR25343. However, we feel that the compiler could be smarter in these cases. For example, the compiler could recognize that it is generating the same function when instantiating the second instance of foo and reuse the first one instead of creating another one. This would prevent the creation of two identically mangled names which caused the error seen above. Or perhaps the compiler could be smarter and when it encounters the second instantiation of foo, it would issue an error at that point with a useful diagnostic.

Thoughts?

Douglas Yung
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160203/4ae40025/attachment.html>


More information about the cfe-dev mailing list