diff options
| -rw-r--r-- | clang/Driver/clang.cpp | 11 | ||||
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.def | 2 | ||||
| -rw-r--r-- | clang/include/clang/Basic/LangOptions.h | 3 | ||||
| -rw-r--r-- | clang/lib/Sema/Sema.h | 4 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 17 | ||||
| -rw-r--r-- | clang/test/Sema/typedef-retain.c | 2 | ||||
| -rw-r--r-- | clang/test/Sema/vector-assign.c | 26 | 
7 files changed, 40 insertions, 25 deletions
diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index 5e545b98e44..52f34783c1f 100644 --- a/clang/Driver/clang.cpp +++ b/clang/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/clang/include/clang/Basic/DiagnosticSemaKinds.def b/clang/include/clang/Basic/DiagnosticSemaKinds.def index 8b3bd1510a5..89577dfd392 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.def +++ b/clang/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/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index daae904823a..b615412f20b 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/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/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h index 6e3a5526864..45f08bc8df5 100644 --- a/clang/lib/Sema/Sema.h +++ b/clang/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/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 129967a14b6..ddd5349c156 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/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/clang/test/Sema/typedef-retain.c b/clang/test/Sema/typedef-retain.c index 861e0771cc4..641b7ec0328 100644 --- a/clang/test/Sema/typedef-retain.c +++ b/clang/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/clang/test/Sema/vector-assign.c b/clang/test/Sema/vector-assign.c index be447120c51..548c08e7e32 100644 --- a/clang/test/Sema/vector-assign.c +++ b/clang/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  | 

