[cfe-commits] r44449 - in /cfe/trunk: Driver/clang.cpp Sema/SemaExpr.cpp include/clang/Basic/LangOptions.h test/Sema/vector-assign.c
Anders Carlsson
andersca at mac.com
Thu Nov 29 20:21:23 PST 2007
Author: andersca
Date: Thu Nov 29 22:21:22 2007
New Revision: 44449
URL: http://llvm.org/viewvc/llvm-project?rev=44449&view=rev
Log:
Support lax vector conversions.
Added:
cfe/trunk/test/Sema/vector-assign.c
Modified:
cfe/trunk/Driver/clang.cpp
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/Basic/LangOptions.h
Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=44449&r1=44448&r2=44449&view=diff
==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Thu Nov 29 22:21:22 2007
@@ -282,6 +282,12 @@
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 @@
Options.DollarIdents = 1; // FIXME: Really a target property.
Options.PascalStrings = PascalStrings;
Options.WritableStrings = WritableStrings;
+ Options.LaxVectorConversions = LaxVectorConversions;
}
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=44449&r1=44448&r2=44449&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Thu Nov 29 22:21:22 2007
@@ -1100,9 +1100,22 @@
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())
Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=44449&r1=44448&r2=44449&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Thu Nov 29 22:21:22 2007
@@ -37,7 +37,8 @@
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;
Added: cfe/trunk/test/Sema/vector-assign.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vector-assign.c?rev=44449&view=auto
==============================================================================
--- cfe/trunk/test/Sema/vector-assign.c (added)
+++ cfe/trunk/test/Sema/vector-assign.c Thu Nov 29 22:21:22 2007
@@ -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'}}
+}
More information about the cfe-commits
mailing list