summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-01-30 23:17:46 +0000
committerAnders Carlsson <andersca@mac.com>2009-01-30 23:17:46 +0000
commitb0f90ccbc1079bb054071b836aa6dd265f33f3a2 (patch)
treee5fa8070f989fd57284bc5d6f87ec7acbe84a91e
parent014858b69f063cbf7b6513eebe964a9f6224970d (diff)
downloadclang-b0f90ccbc1079bb054071b836aa6dd265f33f3a2.tar.gz
Turn on -flax-vector-conversions by default, issue a warning whenever one is done. Add a -fnolax-vector-conversions option. Fixes PR2862.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63447 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Driver/clang.cpp11
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.def2
-rw-r--r--include/clang/Basic/LangOptions.h3
-rw-r--r--lib/Sema/Sema.h4
-rw-r--r--lib/Sema/SemaExpr.cpp17
-rw-r--r--test/Sema/typedef-retain.c2
-rw-r--r--test/Sema/vector-assign.c26
7 files changed, 40 insertions, 25 deletions
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index 5e545b98e4..52f34783c1 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -486,10 +486,10 @@ 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"));
+NoLaxVectorConversions("fnolax-vector-conversions",
+ llvm::cl::desc("Disallow implicit conversions between "
+ "vectors with a different number of "
+ "elements or different element types"));
static llvm::cl::opt<bool>
EnableBlocks("fblocks", llvm::cl::desc("enable the 'blocks' language feature"), llvm::cl::ValueDisallowed);
@@ -620,7 +620,8 @@ static void InitializeLanguageStandard(LangOptions &Options, LangKind LK,
Options.PascalStrings = PascalStrings;
Options.Microsoft = MSExtensions;
Options.WritableStrings = WritableStrings;
- Options.LaxVectorConversions = LaxVectorConversions;
+ if (NoLaxVectorConversions.getPosition())
+ Options.LaxVectorConversions = 0;
Options.Exceptions = Exceptions;
if (EnableBlocks.getPosition() || DisableBlocks.getPosition())
Options.Blocks = EnableBlocks;
diff --git a/include/clang/Basic/DiagnosticSemaKinds.def b/include/clang/Basic/DiagnosticSemaKinds.def
index 8b3bd1510a..89577dfd39 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.def
+++ b/include/clang/Basic/DiagnosticSemaKinds.def
@@ -878,6 +878,8 @@ DIAG(ext_typecheck_convert_incompatible_pointer, EXTWARN,
"incompatible pointer types %2 %1, expected %0")
DIAG(ext_typecheck_convert_discards_qualifiers, EXTWARN,
"%2 %1 discards qualifiers, expected %0")
+DIAG(warn_incompatible_vectors, WARNING,
+ "incompatible vector types %2 %1, expected %0")
DIAG(err_int_to_block_pointer, ERROR,
"invalid conversion %2 integer %1, expected block pointer %0")
DIAG(err_typecheck_comparison_of_distinct_blocks, ERROR,
diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h
index daae904823..b615412f20 100644
--- a/include/clang/Basic/LangOptions.h
+++ b/include/clang/Basic/LangOptions.h
@@ -66,7 +66,8 @@ public:
GC = ObjC1 = ObjC2 = ObjCNonFragileABI = 0;
C99 = Microsoft = CPlusPlus = CPlusPlus0x = NoExtensions = 0;
CXXOperatorNames = PascalStrings = Boolean = WritableStrings = 0;
- LaxVectorConversions = Exceptions = NeXTRuntime = 0;
+ Exceptions = NeXTRuntime = 0;
+ LaxVectorConversions = 1;
// FIXME: The default should be 1.
ThreadsafeStatics = 0;
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 6e3a552686..45f08bc8df 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -1584,6 +1584,10 @@ public:
/// c/v/r qualifiers, which we accept as an extension.
CompatiblePointerDiscardsQualifiers,
+ /// IncompatibleVectors - The assignment is between two vector types that
+ /// have the same size, which we accept as an extension.
+ IncompatibleVectors,
+
/// IntToBlockPointer - The assignment converts an int to a block
/// pointer. We disallow this.
IntToBlockPointer,
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 129967a14b..ddd5349c15 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2448,7 +2448,7 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) {
if (getLangOptions().LaxVectorConversions &&
lhsType->isVectorType() && rhsType->isVectorType()) {
if (Context.getTypeSize(lhsType) == Context.getTypeSize(rhsType))
- return Compatible;
+ return IncompatibleVectors;
}
return Incompatible;
}
@@ -2599,13 +2599,17 @@ inline QualType Sema::CheckVectorOperands(SourceLocation Loc, Expr *&lex,
// Handle the case of a vector & extvector type of the same size and element
// type. It would be nice if we only had one vector type someday.
- if (getLangOptions().LaxVectorConversions)
- if (const VectorType *LV = lhsType->getAsVectorType())
+ if (getLangOptions().LaxVectorConversions) {
+ // FIXME: Should we warn here?
+ if (const VectorType *LV = lhsType->getAsVectorType()) {
if (const VectorType *RV = rhsType->getAsVectorType())
if (LV->getElementType() == RV->getElementType() &&
- LV->getNumElements() == RV->getNumElements())
+ LV->getNumElements() == RV->getNumElements()) {
return lhsType->isExtVectorType() ? lhsType : rhsType;
-
+ }
+ }
+ }
+
// If the lhs is an extended vector and the rhs is a scalar of the same type
// or a literal, promote the rhs to the vector type.
if (const ExtVectorType *V = lhsType->getAsExtVectorType()) {
@@ -4359,6 +4363,9 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy,
// it can give a more specific diagnostic.
DiagKind = diag::warn_incompatible_qualified_id;
break;
+ case IncompatibleVectors:
+ DiagKind = diag::warn_incompatible_vectors;
+ break;
case Incompatible:
DiagKind = diag::err_typecheck_convert_incompatible;
isInvalid = true;
diff --git a/test/Sema/typedef-retain.c b/test/Sema/typedef-retain.c
index 861e0771cc..641b7ec032 100644
--- a/test/Sema/typedef-retain.c
+++ b/test/Sema/typedef-retain.c
@@ -1,4 +1,4 @@
-// RUN: clang -fsyntax-only -verify %s
+// RUN: clang -fsyntax-only -verify %s -fnolax-vector-conversions
typedef float float4 __attribute__((vector_size(16)));
typedef int int4 __attribute__((vector_size(16)));
diff --git a/test/Sema/vector-assign.c b/test/Sema/vector-assign.c
index be447120c5..548c08e7e3 100644
--- a/test/Sema/vector-assign.c
+++ b/test/Sema/vector-assign.c
@@ -1,4 +1,4 @@
-// RUN: clang %s -verify -fsyntax-only -flax-vector-conversions
+// RUN: clang %s -verify -fsyntax-only
typedef unsigned int v2u __attribute__ ((vector_size (8)));
typedef signed int v2s __attribute__ ((vector_size (8)));
typedef signed int v1s __attribute__ ((vector_size (4)));
@@ -12,30 +12,30 @@ void f() {
v2f v4;
v4ss v5;
- v1 = v2;
+ v1 = v2; // expected-warning {{incompatible vector types assigning 'v2u', expected 'v2s'}}
v1 = v3; // expected-error {{incompatible type assigning 'v1s', expected 'v2s'}}
- v1 = v4;
- v1 = v5;
+ v1 = v4; // expected-warning {{incompatible vector types assigning 'v2f', expected 'v2s'}}
+ v1 = v5; // expected-warning {{incompatible vector types assigning 'v4ss', expected 'v2s'}}
- v2 = v1;
+ v2 = v1; // expected-warning {{incompatible vector types assigning 'v2s', expected 'v2u'}}
v2 = v3; // expected-error {{incompatible type assigning 'v1s', expected 'v2u'}}
- v2 = v4;
- v2 = v5;
+ v2 = v4; // expected-warning {{incompatible vector types assigning 'v2f', expected 'v2u'}}
+ v2 = v5; // expected-warning {{incompatible vector types assigning 'v4ss', expected 'v2u'}}
v3 = v1; // expected-error {{incompatible type assigning 'v2s', expected 'v1s'}}
v3 = v2; // expected-error {{incompatible type assigning 'v2u', expected 'v1s'}}
v3 = v4; // expected-error {{incompatible type assigning 'v2f', expected 'v1s'}}
v3 = v5; // expected-error {{incompatible type assigning 'v4ss', expected 'v1s'}}
- v4 = v1;
- v4 = v2;
+ v4 = v1; // expected-warning {{incompatible vector types assigning 'v2s', expected 'v2f'}}
+ v4 = v2; // expected-warning {{incompatible vector types assigning 'v2u', expected 'v2f'}}
v4 = v3; // expected-error {{incompatible type assigning 'v1s', expected 'v2f'}}
- v4 = v5;
+ v4 = v5; // expected-warning {{incompatible vector types assigning 'v4ss', expected 'v2f'}}
- v5 = v1;
- v5 = v2;
+ v5 = v1; // expected-warning {{incompatible vector types assigning 'v2s', expected 'v4ss'}}
+ v5 = v2; // expected-warning {{incompatible vector types assigning 'v2u', expected 'v4ss'}}
v5 = v3; // expected-error {{incompatible type assigning 'v1s', expected 'v4ss'}}
- v5 = v4;
+ v5 = v4; // expected-warning {{incompatible vector types assigning 'v2f', expected 'v4ss'}}
}
// PR2263