]> granicus.if.org Git - clang/commitdiff
Support lax vector conversions.
authorAnders Carlsson <andersca@mac.com>
Fri, 30 Nov 2007 04:21:22 +0000 (04:21 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 30 Nov 2007 04:21:22 +0000 (04:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44449 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/clang.cpp
Sema/SemaExpr.cpp
include/clang/Basic/LangOptions.h
test/Sema/vector-assign.c [new file with mode: 0644]

index f85ab52cc77c3ca144932236e5dfba2a1d4926a5..ac3a04ab2e92c6226e8336bd41f103cb8bef32a4 100644 (file)
@@ -282,6 +282,12 @@ PascalStrings("fpascal-strings",
 static llvm::cl::opt<bool>
 WritableStrings("fwritable-strings",
               llvm::cl::desc("Store string literals as writable data."));
+
+static llvm::cl::opt<bool>
+LaxVectorConversions("flax-vector-conversions",
+                     llvm::cl::desc("Allow implicit conversions between vectors"
+                                    " with a different number of elements or "
+                                    "different element types."));
 // FIXME: add:
 //   -ansi
 //   -trigraphs
@@ -340,6 +346,7 @@ static void InitializeLanguageStandard(LangOptions &Options) {
   Options.DollarIdents = 1;  // FIXME: Really a target property.
   Options.PascalStrings = PascalStrings;
   Options.WritableStrings = WritableStrings;
+  Options.LaxVectorConversions = LaxVectorConversions;
 }
 
 //===----------------------------------------------------------------------===//
index 336dca716e47818a90b398f57b4af52322881dbf..f53980ca906d14913cdf3cfbdc298db6c2528e4d 100644 (file)
@@ -1100,9 +1100,22 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) {
       return Compatible;
   } else if (lhsType->isArithmeticType() && rhsType->isArithmeticType()) {
     if (lhsType->isVectorType() || rhsType->isVectorType()) {
-      if (lhsType.getCanonicalType() != rhsType.getCanonicalType())
+      if (!getLangOptions().LaxVectorConversions) {
+        if (lhsType.getCanonicalType() != rhsType.getCanonicalType())
+          return Incompatible;
+      } else {
+        if (lhsType->isVectorType() && rhsType->isVectorType()) {
+          if ((lhsType->isIntegerType() && rhsType->isIntegerType()) ||
+              (lhsType->isRealFloatingType() && 
+               rhsType->isRealFloatingType())) {
+            if (Context.getTypeSize(lhsType, SourceLocation()) == 
+                Context.getTypeSize(rhsType, SourceLocation()))
+              return Compatible;
+          }
+        }
         return Incompatible;
-    }
+      }
+    }      
     return Compatible;
   } else if (lhsType->isPointerType()) {
     if (rhsType->isIntegerType())
index d88dc4b9f9f93a4093be317f4009789f0d29ed79..77ae3696930bb86abbee06e88635b8764db28d0c 100644 (file)
@@ -37,7 +37,8 @@ struct LangOptions {
   unsigned PascalStrings     : 1;  // Allow Pascal strings
   unsigned Boolean           : 1;  // Allow bool/true/false
   unsigned WritableStrings   : 1;  // Allow writable strings
-  
+  unsigned LaxVectorConversions : 1;
+    
   LangOptions() {
     Trigraphs = BCPLComment = DollarIdents = Digraphs = HexFloats = 0;
     ObjC1 = ObjC2 = 0;
diff --git a/test/Sema/vector-assign.c b/test/Sema/vector-assign.c
new file mode 100644 (file)
index 0000000..ff64422
--- /dev/null
@@ -0,0 +1,39 @@
+// RUN: clang %s -verify -fsyntax-only -flax-vector-conversions
+typedef unsigned int v2u __attribute__ ((vector_size (8)));
+typedef signed int v2s __attribute__ ((vector_size (8)));
+typedef signed int v1s __attribute__ ((vector_size (4)));
+typedef float v2f __attribute__ ((vector_size(8)));
+typedef signed short v4ss __attribute__ ((vector_size (8)));
+
+void f() {
+  v2s v1;
+  v2u v2;
+  v1s v3;
+  v2f v4;
+  v4ss v5;
+  
+  v1 = v2; 
+  v1 = v3; // expected-error {{incompatible types assigning 'v1s' to 'v2s'}}
+  v1 = v4; // expected-error {{incompatible types assigning 'v2f' to 'v2s'}}
+  v1 = v5;
+  
+  v2 = v1;
+  v2 = v3; // expected-error {{incompatible types assigning 'v1s' to 'v2u'}}
+  v2 = v4; // expected-error {{incompatible types assigning 'v2f' to 'v2u'}}
+  v2 = v5;
+  
+  v3 = v1; // expected-error {{incompatible types assigning 'v2s' to 'v1s'}}
+  v3 = v2; // expected-error {{incompatible types assigning 'v2u' to 'v1s'}}
+  v3 = v4; // expected-error {{incompatible types assigning 'v2f' to 'v1s'}}
+  v3 = v5; // expected-error {{incompatible types assigning 'v4ss' to 'v1s'}}
+  
+  v4 = v1; // expected-error {{incompatible types assigning 'v2s' to 'v2f'}}
+  v4 = v2; // expected-error {{incompatible types assigning 'v2u' to 'v2f'}}
+  v4 = v3; // expected-error {{incompatible types assigning 'v1s' to 'v2f'}}
+  v4 = v5; // expected-error {{incompatible types assigning 'v4ss' to 'v2f'}}
+  
+  v5 = v1;
+  v5 = v2;
+  v5 = v3; // expected-error {{incompatible types assigning 'v1s' to 'v4ss'}}
+  v5 = v4; // expected-error {{incompatible types assigning 'v2f' to 'v4ss'}}
+}