Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Problem with '==' and vectors #7996

Open Quuxplusone opened 14 years ago

Quuxplusone commented 14 years ago
Bugzilla Link PR7553
Status NEW
Importance P normal
Reported by John Thompson (John.Thompson.JTSoftware@gmail.com)
Reported on 2010-07-01 17:22:36 -0700
Last modified on 2010-11-04 22:35:01 -0700
Version trunk
Hardware PC Windows XP
CC
Fixed by commit(s)
Attachments fix_for_7553.patch (12946 bytes, text/plain)
Blocks
Blocked by
See also
The code:

void func()
{
    static vector float v1;
    static vector float v2;
    if (v1 == v2)
        return;
}

The error:

>clang -cc1 -triple=ppu-unknown-lv2 -faltivec vecindex.cpp
vecindex.cpp:5:6: error: value of type 'int
__attribute__((ext_vector_type(4)))' is not contextually convertible to 'bool'
        if (v1 == v2)
            ^~~~~~~~
1 error generated.
Quuxplusone commented 14 years ago
I have a partial fix for this on the parser-side, but because there are code
generation issues, I'm holding off a bit to confer with another Clang developer
who is working on the Altivec support in general.

Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp   (revision 107347)
+++ lib/Sema/SemaExpr.cpp   (working copy)
@@ -5643,6 +5643,11 @@
   if (vType.isNull())
     return vType;

+  // If AltiVec, the comparison results in a numeric type, i.e.
+  // bool for C++, int for C
+  if (getLangOptions().AltiVec)
+    return (getLangOptions().CPlusPlus ? Context.BoolTy : Context.IntTy);
+
   QualType lType = lex->getType();
   QualType rType = rex->getType();

...  Plus some tests.
Quuxplusone commented 13 years ago

Attached fix_for_7553.patch (12946 bytes, text/plain): patch