[cfe-commits] r63447 - in /cfe/trunk: Driver/clang.cpp include/clang/Basic/DiagnosticSemaKinds.def include/clang/Basic/LangOptions.h lib/Sema/Sema.h lib/Sema/SemaExpr.cpp test/Sema/typedef-retain.c test/Sema/vector-assign.c
Anders Carlsson
andersca at mac.com
Fri Jan 30 15:17:46 PST 2009
Author: andersca
Date: Fri Jan 30 17:17:46 2009
New Revision: 63447
URL: http://llvm.org/viewvc/llvm-project?rev=63447&view=rev
Log:
Turn on -flax-vector-conversions by default, issue a warning whenever one is done. Add a -fnolax-vector-conversions option. Fixes PR2862.
Modified:
cfe/trunk/Driver/clang.cpp
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/typedef-retain.c
cfe/trunk/test/Sema/vector-assign.c
Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=63447&r1=63446&r2=63447&view=diff
==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Fri Jan 30 17:17:46 2009
@@ -486,10 +486,10 @@
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 @@
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;
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def?rev=63447&r1=63446&r2=63447&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Fri Jan 30 17:17:46 2009
@@ -878,6 +878,8 @@
"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,
Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=63447&r1=63446&r2=63447&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Fri Jan 30 17:17:46 2009
@@ -66,7 +66,8 @@
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;
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=63447&r1=63446&r2=63447&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri Jan 30 17:17:46 2009
@@ -1584,6 +1584,10 @@
/// 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,
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=63447&r1=63446&r2=63447&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Jan 30 17:17:46 2009
@@ -2448,7 +2448,7 @@
if (getLangOptions().LaxVectorConversions &&
lhsType->isVectorType() && rhsType->isVectorType()) {
if (Context.getTypeSize(lhsType) == Context.getTypeSize(rhsType))
- return Compatible;
+ return IncompatibleVectors;
}
return Incompatible;
}
@@ -2599,13 +2599,17 @@
// 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 @@
// 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;
Modified: cfe/trunk/test/Sema/typedef-retain.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/typedef-retain.c?rev=63447&r1=63446&r2=63447&view=diff
==============================================================================
--- cfe/trunk/test/Sema/typedef-retain.c (original)
+++ cfe/trunk/test/Sema/typedef-retain.c Fri Jan 30 17:17:46 2009
@@ -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)));
Modified: cfe/trunk/test/Sema/vector-assign.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vector-assign.c?rev=63447&r1=63446&r2=63447&view=diff
==============================================================================
--- cfe/trunk/test/Sema/vector-assign.c (original)
+++ cfe/trunk/test/Sema/vector-assign.c Fri Jan 30 17:17:46 2009
@@ -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 @@
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
More information about the cfe-commits
mailing list