]> granicus.if.org Git - clang/commitdiff
Turn on -flax-vector-conversions by default, issue a warning whenever one is done...
authorAnders Carlsson <andersca@mac.com>
Fri, 30 Jan 2009 23:17:46 +0000 (23:17 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 30 Jan 2009 23:17:46 +0000 (23:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63447 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 5e545b98e44b73698d9ab09e4a52d4c0f0ee121f..52f34783c1f2ce96995248e4225ec140f3b9c204 100644 (file)
@@ -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;
index 8b3bd1510a52b7aebf0338a108a97beced4678cb..89577dfd3922c827fa0d2120583e1380daac73f3 100644 (file)
@@ -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,
index daae904823a79e7b2c3d1ca1a70fd87d95b1d62e..b615412f20b69a61621c57ed8247af2f354712dd 100644 (file)
@@ -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;
index 6e3a552686443f16ec950d15e86a66bbcf78bc8f..45f08bc8df595d450f5b5d6bea2960ade3682320 100644 (file)
@@ -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,
index 129967a14b624e907fba52c074f28d8088e93490..ddd5349c1564605f77a3a37616891332d2cc5800 100644 (file)
@@ -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;
index 861e0771cc42deec76179a6198377cb22357d1e7..641b7ec0328880c73989468dda1768a5c7bde185 100644 (file)
@@ -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)));
index be447120c51ce383925bb75e1a6962f965eb8927..548c08e7e32aed66450fbbd767d38a11cbc595d1 100644 (file)
@@ -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