Re: [PATCH] D24669: {Sema] Gcc compatibility of vector shift.
vbyakovlcl added a comment. Clang 3.8 balances vector shift operand erroneous using CheckVectorOperands which converts one of operand to the type of another. In https://reviews.llvm.org/D21678 it was fixed by using checkVectorShift instead. As result clang does not emit error if shift operands have different element sizes (bat gcc does). Repository: rL LLVM https://reviews.llvm.org/D24669 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24669: {Sema] Gcc compatibility of vector shift.
vbyakovlcl added inline comments. Comment at: llvm/tools/clang/include/clang/Basic/DiagnosticGroups.td:522 @@ -521,2 +521,3 @@ def GNUZeroVariadicMacroArguments : DiagGroup<"gnu-zero-variadic-macro-arguments">; +def GNUVecElemSize : DiagGroup<"gnu-vec-elem-size">; def Fallback : DiagGroup<"fallback">; aaron.ballman wrote: > Is this the same warning flag GCC uses? Gcc prints error messages t.c:21:13: error: invalid operands to binary << (have vector_int8 and vector_short8) vi8 = vi8 << vs8; I could not find a flag controlling this error. Comment at: llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td:2306 @@ -2304,1 +2305,3 @@ + "vector operands do not have the same elements sizes (%0 and %1)">, + InGroup, DefaultIgnore; def err_ext_vector_component_exceeds_length : Error< aaron.ballman wrote: > Why is this off by default? The question is: would we like to have the feature as a clang extension? Repository: rL LLVM https://reviews.llvm.org/D24669 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D24669: {Sema] Gcc compatibility of vector shift.
vbyakovlcl added inline comments. > aaron.ballman wrote in DiagnosticGroups.td:522 > I would not add this as a diagnostic group, but instead use an ad-hoc group > on the diagnostic itself. I don't think this is going to see very many > diagnostics covered by the same group, but if that turns out to be the case, > we can switch then. Ok, done > aaron.ballman wrote in DiagnosticSemaKinds.td:2306 > I'm not the best one to answer that question, but we typically avoid adding > new off-by-default diagnostics. Since GCC prints this as an error message and > this patch is for GCC compatibility, it seems weird to me to add this as an > off-by-default warning. I did similar to GCC - error by default. https://reviews.llvm.org/D24669 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D24669: {Sema] Gcc compatibility of vector shift.
vbyakovlcl removed rL LLVM as the repository for this revision. vbyakovlcl updated this revision to Diff 73468. https://reviews.llvm.org/D24669 Files: llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td llvm/tools/clang/lib/Sema/SemaExpr.cpp llvm/tools/clang/test/Sema/vecshift.c Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp === --- llvm/tools/clang/lib/Sema/SemaExpr.cpp +++ llvm/tools/clang/lib/Sema/SemaExpr.cpp @@ -8784,6 +8784,65 @@ << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); return QualType(); } +if (!S.LangOpts.OpenCL && !S.LangOpts.ZVector) { + const BuiltinType *LHSBT = LHSEleType->getAs(); + const BuiltinType *RHSBT = RHSEleType->getAs(); + if (LHSBT != RHSBT) { +BuiltinType::Kind LHSKind = LHSBT->getKind(); +BuiltinType::Kind RHSKind = RHSBT->getKind(); +bool DiffSizes = true; +switch (LHSKind) { +case BuiltinType::Char_S: + DiffSizes = + RHSKind != BuiltinType::Char_U && RHSKind != BuiltinType::UChar; + break; +case BuiltinType::Char_U: + DiffSizes = + RHSKind != BuiltinType::Char_S && RHSKind != BuiltinType::UChar; + break; +case BuiltinType::UChar: + DiffSizes = + RHSKind != BuiltinType::Char_U && RHSKind != BuiltinType::Char_S; + break; +case BuiltinType::Short: + DiffSizes = RHSKind != BuiltinType::UShort; + break; +case BuiltinType::UShort: + DiffSizes = RHSKind != BuiltinType::Short; + break; +case BuiltinType::Int: + DiffSizes = RHSKind != BuiltinType::UInt; + break; +case BuiltinType::UInt: + DiffSizes = RHSKind != BuiltinType::Int; + break; +case BuiltinType::Long: + DiffSizes = RHSKind != BuiltinType::ULong; + break; +case BuiltinType::ULong: + DiffSizes = RHSKind != BuiltinType::Long; + break; +case BuiltinType::LongLong: + DiffSizes = RHSKind != BuiltinType::ULongLong; + break; +case BuiltinType::ULongLong: + DiffSizes = RHSKind != BuiltinType::LongLong; + break; +default: + DiffSizes = true; + break; +} +if (DiffSizes) { + S.Diag(Loc, diag::warn_typecheck_vector_element_sizes_not_equal) + << LHS.get()->getType() << RHS.get()->getType() + << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + if (S.Diags.getDiagnosticLevel( + diag::warn_typecheck_vector_element_sizes_not_equal, Loc) == + DiagnosticsEngine::Level::Error) +return QualType(); +} + } +} } else { // ...else expand RHS to match the number of elements in LHS. QualType VecTy = Index: llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td === --- llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -2301,6 +2301,9 @@ "cannot convert between vector and non-scalar values (%0 and %1)">; def err_typecheck_vector_lengths_not_equal : Error< "vector operands do not have the same number of elements (%0 and %1)">; +def warn_typecheck_vector_element_sizes_not_equal : Warning< + "vector operands do not have the same elements sizes (%0 and %1)">, + InGroup>, DefaultError; def err_ext_vector_component_exceeds_length : Error< "vector component access exceeds type %0">; def err_ext_vector_component_name_illegal : Error< Index: llvm/tools/clang/test/Sema/vecshift.c === --- llvm/tools/clang/test/Sema/vecshift.c +++ llvm/tools/clang/test/Sema/vecshift.c @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -DERR -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wno-error-gnu-vec-elem-size -verify %s typedef __attribute__((__ext_vector_type__(8))) char vector_char8; typedef __attribute__((__ext_vector_type__(8))) short vector_short8; @@ -48,16 +49,30 @@ vus8 = 1 << vus8; vc8 = vc8 << vc8; - vi8 = vi8 << vuc8; - vuc8 = vuc8 << vi8; - vus8 = vus8 << vui8; - vui8 = vui8 << vs8; +#ifdef ERR + vi8 = vi8 << vuc8; // expected-error {{vector operands do not have the same elements sizes}} + vuc8 = vuc8 << vi8; // expected-error {{vector operands do not have the same elements sizes}} + vus8 = vus8 << vui8; // expected-error {{vector operands do not have the same elements sizes}} + vui8 = vui8 << vs8; // expected-error {{vector operands do not have the same elements sizes}} +#else + vi8 = vi8 << vuc8; // expected-warning {{vector operands do not have the same elements sizes}} + vuc8 = vuc8 << vi8; // expected-warning {{vector oper
[PATCH] D24669: {Sema] Gcc compatibility of vector shift.
vbyakovlcl updated this revision to Diff 73642. https://reviews.llvm.org/D24669 Files: llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td llvm/tools/clang/lib/Sema/SemaExpr.cpp llvm/tools/clang/test/CodeGen/vecshift.c llvm/tools/clang/test/Sema/vecshift.c Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp === --- llvm/tools/clang/lib/Sema/SemaExpr.cpp +++ llvm/tools/clang/lib/Sema/SemaExpr.cpp @@ -8784,6 +8784,20 @@ << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); return QualType(); } +if (!S.LangOpts.OpenCL && !S.LangOpts.ZVector) { + const BuiltinType *LHSBT = LHSEleType->getAs(); + const BuiltinType *RHSBT = RHSEleType->getAs(); + if (LHSBT != RHSBT && + S.Context.getTypeSize(LHSBT) != S.Context.getTypeSize(RHSBT)) { +S.Diag(Loc, diag::warn_typecheck_vector_element_sizes_not_equal) +<< LHS.get()->getType() << RHS.get()->getType() +<< LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); +if (S.Diags.getDiagnosticLevel( +diag::warn_typecheck_vector_element_sizes_not_equal, Loc) == +DiagnosticsEngine::Level::Error) + return QualType(); + } +} } else { // ...else expand RHS to match the number of elements in LHS. QualType VecTy = Index: llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td === --- llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -2301,6 +2301,9 @@ "cannot convert between vector and non-scalar values (%0 and %1)">; def err_typecheck_vector_lengths_not_equal : Error< "vector operands do not have the same number of elements (%0 and %1)">; +def warn_typecheck_vector_element_sizes_not_equal : Warning< + "vector operands do not have the same elements sizes (%0 and %1)">, + InGroup>, DefaultError; def err_ext_vector_component_exceeds_length : Error< "vector component access exceeds type %0">; def err_ext_vector_component_name_illegal : Error< Index: llvm/tools/clang/test/CodeGen/vecshift.c === --- llvm/tools/clang/test/CodeGen/vecshift.c +++ llvm/tools/clang/test/CodeGen/vecshift.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -Wno-error-gnu-vec-elem-size -emit-llvm %s -o - | FileCheck %s typedef __attribute__((__ext_vector_type__(8))) char vector_char8; typedef __attribute__((__ext_vector_type__(8))) short vector_short8; Index: llvm/tools/clang/test/Sema/vecshift.c === --- llvm/tools/clang/test/Sema/vecshift.c +++ llvm/tools/clang/test/Sema/vecshift.c @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -DERR -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wno-error-gnu-vec-elem-size -verify %s typedef __attribute__((__ext_vector_type__(8))) char vector_char8; typedef __attribute__((__ext_vector_type__(8))) short vector_short8; @@ -48,16 +49,30 @@ vus8 = 1 << vus8; vc8 = vc8 << vc8; - vi8 = vi8 << vuc8; - vuc8 = vuc8 << vi8; - vus8 = vus8 << vui8; - vui8 = vui8 << vs8; +#ifdef ERR + vi8 = vi8 << vuc8; // expected-error {{vector operands do not have the same elements sizes}} + vuc8 = vuc8 << vi8; // expected-error {{vector operands do not have the same elements sizes}} + vus8 = vus8 << vui8; // expected-error {{vector operands do not have the same elements sizes}} + vui8 = vui8 << vs8; // expected-error {{vector operands do not have the same elements sizes}} +#else + vi8 = vi8 << vuc8; // expected-warning {{vector operands do not have the same elements sizes}} + vuc8 = vuc8 << vi8; // expected-warning {{vector operands do not have the same elements sizes}} + vus8 = vus8 << vui8; // expected-warning {{vector operands do not have the same elements sizes}} + vui8 = vui8 << vs8; // expected-warning {{vector operands do not have the same elements sizes}} +#endif vc8 <<= vc8; - vi8 <<= vuc8; - vuc8 <<= vi8; - vus8 <<= vui8; - vui8 <<= vs8; +#ifdef ERR + vi8 <<= vuc8; // expected-error {{vector operands do not have the same elements sizes}} + vuc8 <<= vi8; // expected-error {{vector operands do not have the same elements sizes}} + vus8 <<= vui8; // expected-error {{vector operands do not have the same elements sizes}} + vui8 <<= vs8; // expected-error {{vector operands do not have the same elements sizes}} +#else + vi8 <<= vuc8; // expected-warning {{vector operands do not have the same elements sizes}} + vuc8 <<= vi8; // expected-warning {{vector operands do not have the same elements sizes}} + vus8 <<= vui8; // expected-warning {{vector operands do not have the same elements sizes}} + vui8 <<= vs8; // expected-warning {{vector ope
[PATCH] D24669: {Sema] Gcc compatibility of vector shift.
vbyakovlcl added inline comments. > ahatanak wrote in SemaExpr.cpp:8787 > Is it possible to use ASTContext::getTypeSize here? You are right. https://reviews.llvm.org/D24669 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D24669: {Sema] Gcc compatibility of vector shift.
vbyakovlcl updated this revision to Diff 74123. https://reviews.llvm.org/D24669 Files: llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td llvm/tools/clang/lib/Sema/SemaExpr.cpp llvm/tools/clang/test/CodeGen/vecshift.c llvm/tools/clang/test/Sema/vecshift.c Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp === --- llvm/tools/clang/lib/Sema/SemaExpr.cpp +++ llvm/tools/clang/lib/Sema/SemaExpr.cpp @@ -8784,6 +8784,20 @@ << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); return QualType(); } +if (!S.LangOpts.OpenCL && !S.LangOpts.ZVector) { + const BuiltinType *LHSBT = LHSEleType->getAs(); + const BuiltinType *RHSBT = RHSEleType->getAs(); + if (LHSBT != RHSBT && + S.Context.getTypeSize(LHSBT) != S.Context.getTypeSize(RHSBT)) { +S.Diag(Loc, diag::warn_typecheck_vector_element_sizes_not_equal) +<< LHS.get()->getType() << RHS.get()->getType() +<< LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); +if (S.Diags.getDiagnosticLevel( +diag::warn_typecheck_vector_element_sizes_not_equal, Loc) == +DiagnosticsEngine::Level::Error) + return QualType(); + } +} } else { // ...else expand RHS to match the number of elements in LHS. QualType VecTy = Index: llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td === --- llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -2301,6 +2301,9 @@ "cannot convert between vector and non-scalar values (%0 and %1)">; def err_typecheck_vector_lengths_not_equal : Error< "vector operands do not have the same number of elements (%0 and %1)">; +def warn_typecheck_vector_element_sizes_not_equal : Warning< + "vector operands do not have the same elements sizes (%0 and %1)">, + InGroup>, DefaultError; def err_ext_vector_component_exceeds_length : Error< "vector component access exceeds type %0">; def err_ext_vector_component_name_illegal : Error< Index: llvm/tools/clang/test/CodeGen/vecshift.c === --- llvm/tools/clang/test/CodeGen/vecshift.c +++ llvm/tools/clang/test/CodeGen/vecshift.c @@ -1,5 +1,7 @@ -// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -Wno-error-vec-elem-size -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -Wno-error-vec-elem-size -DEXT -emit-llvm %s -o - | FileCheck %s +#ifdef EXT typedef __attribute__((__ext_vector_type__(8))) char vector_char8; typedef __attribute__((__ext_vector_type__(8))) short vector_short8; typedef __attribute__((__ext_vector_type__(8))) int vector_int8; @@ -12,6 +14,20 @@ typedef __attribute__((__ext_vector_type__(4))) unsigned char vector_uchar4; typedef __attribute__((__ext_vector_type__(4))) unsigned short vector_ushort4; typedef __attribute__((__ext_vector_type__(4))) unsigned int vector_uint4; +#else +typedef __attribute__((vector_size(8))) char vector_char8; +typedef __attribute__((vector_size(16))) short vector_short8; +typedef __attribute__((vector_size(32))) int vector_int8; +typedef __attribute__((vector_size(8))) unsigned char vector_uchar8; +typedef __attribute__((vector_size(16))) unsigned short vector_ushort8; +typedef __attribute__((vector_size(32))) unsigned int vector_uint8; +typedef __attribute__((vector_size(4))) char vector_char4; +typedef __attribute__((vector_size(4))) short vector_short4; +typedef __attribute__((vector_size(16))) int vector_int4; +typedef __attribute__((vector_size(4))) unsigned char vector_uchar4; +typedef __attribute__((vector_size(8))) unsigned short vector_ushort4; +typedef __attribute__((vector_size(16))) unsigned int vector_uint4; +#endif char c; short s; Index: llvm/tools/clang/test/Sema/vecshift.c === --- llvm/tools/clang/test/Sema/vecshift.c +++ llvm/tools/clang/test/Sema/vecshift.c @@ -1,5 +1,9 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -DERR -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wno-error-vec-elem-size -verify %s +// RUN: %clang_cc1 -fsyntax-only -DEXT -DERR -verify %s +// RUN: %clang_cc1 -fsyntax-only -DEXT -Wno-error-vec-elem-size -verify %s +#ifdef EXT typedef __attribute__((__ext_vector_type__(8))) char vector_char8; typedef __attribute__((__ext_vector_type__(8))) short vector_short8; typedef __attribute__((__ext_vector_type__(8))) int vector_int8; @@ -12,6 +16,20 @@ typedef __attribute__((__ext_vector_type__(4))) unsigned char vector_uchar4; typedef __attribute__((__ext_vector_type__(4))) unsigned short vector_ushort4; typedef __attribute__((__ext_vector_type__(4))) unsigned int vector_uint4; +#else +typedef __attribute__((vector_size(8))) char vector_char8; +typedef __attribute__
[PATCH] D24669: {Sema] Gcc compatibility of vector shift.
vbyakovlcl added inline comments. Comment at: llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td:2306 + "vector operands do not have the same elements sizes (%0 and %1)">, + InGroup>, DefaultError; def err_ext_vector_component_exceeds_length : Error< bruno wrote: > Although the motivation is to support the same warning present in GCC, I > think this is helpful enough anyway so that we might skip calling it > "gnu-vec-elem-size" and have a more generic name instead? How about plain > "vec-elem-size"? I'm agree. Comment at: llvm/tools/clang/lib/Sema/SemaExpr.cpp:8787 } +if (!S.LangOpts.OpenCL && !S.LangOpts.ZVector) { + const BuiltinType *LHSBT = LHSEleType->getAs(); bruno wrote: > Besides `__ext_vector_type__`, would this also trigger for `vector_size`? > Right now this is an error for `vector_size` primarily because the number of > elements is different, can you confirm this won't change? I compare vector element sizes, so there must not be any differencies caused by different triggers. I added additional type definitions to the tests. All compiles fain. https://reviews.llvm.org/D24669 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D24669: {Sema] Gcc compatibility of vector shift.
vbyakovlcl updated this revision to Diff 74269. https://reviews.llvm.org/D24669 Files: llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td llvm/tools/clang/lib/Sema/SemaExpr.cpp llvm/tools/clang/test/CodeGen/vecshift.c llvm/tools/clang/test/Sema/vecshift.c Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp === --- llvm/tools/clang/lib/Sema/SemaExpr.cpp +++ llvm/tools/clang/lib/Sema/SemaExpr.cpp @@ -8784,6 +8784,16 @@ << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); return QualType(); } +if (!S.LangOpts.OpenCL && !S.LangOpts.ZVector) { + const BuiltinType *LHSBT = LHSEleType->getAs(); + const BuiltinType *RHSBT = RHSEleType->getAs(); + if (LHSBT != RHSBT && + S.Context.getTypeSize(LHSBT) != S.Context.getTypeSize(RHSBT)) { +S.Diag(Loc, diag::warn_typecheck_vector_element_sizes_not_equal) +<< LHS.get()->getType() << RHS.get()->getType() +<< LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + } +} } else { // ...else expand RHS to match the number of elements in LHS. QualType VecTy = Index: llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td === --- llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -2301,6 +2301,9 @@ "cannot convert between vector and non-scalar values (%0 and %1)">; def err_typecheck_vector_lengths_not_equal : Error< "vector operands do not have the same number of elements (%0 and %1)">; +def warn_typecheck_vector_element_sizes_not_equal : Warning< + "vector operands do not have the same elements sizes (%0 and %1)">, + InGroup>, DefaultError; def err_ext_vector_component_exceeds_length : Error< "vector component access exceeds type %0">; def err_ext_vector_component_name_illegal : Error< Index: llvm/tools/clang/test/CodeGen/vecshift.c === --- llvm/tools/clang/test/CodeGen/vecshift.c +++ llvm/tools/clang/test/CodeGen/vecshift.c @@ -1,5 +1,7 @@ -// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -Wno-error-vec-elem-size -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -Wno-error-vec-elem-size -DEXT -emit-llvm %s -o - | FileCheck %s +#ifdef EXT typedef __attribute__((__ext_vector_type__(8))) char vector_char8; typedef __attribute__((__ext_vector_type__(8))) short vector_short8; typedef __attribute__((__ext_vector_type__(8))) int vector_int8; @@ -12,6 +14,20 @@ typedef __attribute__((__ext_vector_type__(4))) unsigned char vector_uchar4; typedef __attribute__((__ext_vector_type__(4))) unsigned short vector_ushort4; typedef __attribute__((__ext_vector_type__(4))) unsigned int vector_uint4; +#else +typedef __attribute__((vector_size(8))) char vector_char8; +typedef __attribute__((vector_size(16))) short vector_short8; +typedef __attribute__((vector_size(32))) int vector_int8; +typedef __attribute__((vector_size(8))) unsigned char vector_uchar8; +typedef __attribute__((vector_size(16))) unsigned short vector_ushort8; +typedef __attribute__((vector_size(32))) unsigned int vector_uint8; +typedef __attribute__((vector_size(4))) char vector_char4; +typedef __attribute__((vector_size(4))) short vector_short4; +typedef __attribute__((vector_size(16))) int vector_int4; +typedef __attribute__((vector_size(4))) unsigned char vector_uchar4; +typedef __attribute__((vector_size(8))) unsigned short vector_ushort4; +typedef __attribute__((vector_size(16))) unsigned int vector_uint4; +#endif char c; short s; Index: llvm/tools/clang/test/Sema/vecshift.c === --- llvm/tools/clang/test/Sema/vecshift.c +++ llvm/tools/clang/test/Sema/vecshift.c @@ -1,5 +1,9 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -DERR -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wno-error-vec-elem-size -verify %s +// RUN: %clang_cc1 -fsyntax-only -DEXT -DERR -verify %s +// RUN: %clang_cc1 -fsyntax-only -DEXT -Wno-error-vec-elem-size -verify %s +#ifdef EXT typedef __attribute__((__ext_vector_type__(8))) char vector_char8; typedef __attribute__((__ext_vector_type__(8))) short vector_short8; typedef __attribute__((__ext_vector_type__(8))) int vector_int8; @@ -12,6 +16,20 @@ typedef __attribute__((__ext_vector_type__(4))) unsigned char vector_uchar4; typedef __attribute__((__ext_vector_type__(4))) unsigned short vector_ushort4; typedef __attribute__((__ext_vector_type__(4))) unsigned int vector_uint4; +#else +typedef __attribute__((vector_size(8))) char vector_char8; +typedef __attribute__((vector_size(16))) short vector_short8; +typedef __attribute__((vector_size(32))) int vector_int8; +typedef __attribute__((vector_size(8))) unsigned char vector_uchar8; +typedef __attribute__((v
[PATCH] D24669: {Sema] Gcc compatibility of vector shift.
vbyakovlcl added inline comments. Comment at: llvm/tools/clang/lib/Sema/SemaExpr.cpp:8787 } +if (!S.LangOpts.OpenCL && !S.LangOpts.ZVector) { + const BuiltinType *LHSBT = LHSEleType->getAs(); bruno wrote: > vbyakovlcl wrote: > > bruno wrote: > > > Besides `__ext_vector_type__`, would this also trigger for `vector_size`? > > > Right now this is an error for `vector_size` primarily because the number > > > of elements is different, can you confirm this won't change? > > I compare vector element sizes, so there must not be any differencies > > caused by different triggers. I added additional type definitions to the > > tests. All compiles fain. > > I don't think this is right. When I try to compile similar code for > `vector_size` without your patch, I get the errors: > > /tmp/x.c:80:15: error: vector operands do not have the same number of > elements ('vector_int8n' (vector of 2 'int' values) and 'vector_uchar8n' > (vector of 8 'unsigned char' values)) > vi8n = vi8n << vuc8n; // expected-warning {{vector operands do not have the > same elements sizes}} > ^ ~ > /tmp/x.c:81:17: error: vector operands do not have the same number of > elements ('vector_uchar8n' (vector of 8 'unsigned char' values) and > 'vector_int8n' (vector of 2 'int' values)) > vuc8n = vuc8n << vi8n; // expected-warning {{vector operands do not have > the same elements sizes}} > ~ ^ > /tmp/x.c:82:17: error: vector operands do not have the same number of > elements ('vector_ushort8n' (vector of 4 'unsigned short' values) and > 'vector_uint8n' (vector of 2 'unsigned int' values)) > vus8n = vus8n << vui8n; // expected-warning {{vector operands do not have > the same elements sizes}} > ~ ^ ~ > /tmp/x.c:83:17: error: vector operands do not have the same number of > elements ('vector_uint8n' (vector of 2 'unsigned int' values) and > 'vector_short8n' (vector of 4 'short' values)) > vui8n = vui8n << vs8n; // expected-warning {{vector operands do not have > the same elements sizes}} > ~ ^ > > Given your test changes, it seems that now, instead of "vector operands do > not have the same number of elements" we would get "vector operands do not > have the same elements sizes". I rather we stay with the first. Additionally, > even if we had "vector operands do not have the same elements sizes" for > `vector_size`, this should never be demoted to a warning. Argument of a GNU vector size attribute specifies vector size measured in bytes(see https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html). So you got right diagnostics. Both compilers with and without my changes print the same diagnostics for yours case. Here is a small testcase used both GNU and clang extensions $ cat bruno.c typedef __attribute__((__ext_vector_type__(8))) int vector_int8; typedef __attribute__((__ext_vector_type__(8))) unsigned char vector_uchar8; typedef __attribute__((vector_size(8))) int vector_int8n; typedef __attribute__((vector_size(8))) unsigned char vector_uchar8n; vector_int8 vi8; vector_uchar8 vuc8; vector_int8n vi8n; vector_uchar8n vuc8n; int foo() { vi8 = vi8 << vuc8; vi8n = vi8n << vuc8n; $ clang -c bruno.c -Wno-error-vec-elem-size bruno.c:13:13: warning: vector operands do not have the same elements sizes ('vector_int8' (vector of 8 'int' values) and 'vector_uchar8' (vector of 8 'unsigned char' values)) [-Wvec-elem-size] vi8 = vi8 << vuc8; ~~~ ^ bruno.c:14:15: error: vector operands do not have the same number of elements ('vector_int8n' (vector of 2 'int' values) and 'vector_uchar8n' (vector of 8 'unsigned char' values)) vi8n = vi8n << vuc8n; The compiler without the changes prints the second error only (bruno.c:14:15). Comment at: llvm/tools/clang/lib/Sema/SemaExpr.cpp:8795-8798 +if (S.Diags.getDiagnosticLevel( +diag::warn_typecheck_vector_element_sizes_not_equal, Loc) == +DiagnosticsEngine::Level::Error) + return QualType(); majnemer wrote: > Why `return QualType()` here? Would returning `LHSType` provide confusing or > incorrect diagnostics? This is really excessive. Thanks. https://reviews.llvm.org/D24669 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D24669: {Sema] Gcc compatibility of vector shift.
vbyakovlcl added inline comments. Comment at: llvm/tools/clang/lib/Sema/SemaExpr.cpp:8787 } +if (!S.LangOpts.OpenCL && !S.LangOpts.ZVector) { + const BuiltinType *LHSBT = LHSEleType->getAs(); bruno wrote: > vbyakovlcl wrote: > > bruno wrote: > > > vbyakovlcl wrote: > > > > bruno wrote: > > > > > Besides `__ext_vector_type__`, would this also trigger for > > > > > `vector_size`? Right now this is an error for `vector_size` primarily > > > > > because the number of elements is different, can you confirm this > > > > > won't change? > > > > I compare vector element sizes, so there must not be any differencies > > > > caused by different triggers. I added additional type definitions to > > > > the tests. All compiles fain. > > > > > > I don't think this is right. When I try to compile similar code for > > > `vector_size` without your patch, I get the errors: > > > > > > /tmp/x.c:80:15: error: vector operands do not have the same number of > > > elements ('vector_int8n' (vector of 2 'int' values) and 'vector_uchar8n' > > > (vector of 8 'unsigned char' values)) > > > vi8n = vi8n << vuc8n; // expected-warning {{vector operands do not have > > > the same elements sizes}} > > > ^ ~ > > > /tmp/x.c:81:17: error: vector operands do not have the same number of > > > elements ('vector_uchar8n' (vector of 8 'unsigned char' values) and > > > 'vector_int8n' (vector of 2 'int' values)) > > > vuc8n = vuc8n << vi8n; // expected-warning {{vector operands do not > > > have the same elements sizes}} > > > ~ ^ > > > /tmp/x.c:82:17: error: vector operands do not have the same number of > > > elements ('vector_ushort8n' (vector of 4 'unsigned short' values) and > > > 'vector_uint8n' (vector of 2 'unsigned int' values)) > > > vus8n = vus8n << vui8n; // expected-warning {{vector operands do not > > > have the same elements sizes}} > > > ~ ^ ~ > > > /tmp/x.c:83:17: error: vector operands do not have the same number of > > > elements ('vector_uint8n' (vector of 2 'unsigned int' values) and > > > 'vector_short8n' (vector of 4 'short' values)) > > > vui8n = vui8n << vs8n; // expected-warning {{vector operands do not > > > have the same elements sizes}} > > > ~ ^ > > > > > > Given your test changes, it seems that now, instead of "vector operands > > > do not have the same number of elements" we would get "vector operands do > > > not have the same elements sizes". I rather we stay with the first. > > > Additionally, even if we had "vector operands do not have the same > > > elements sizes" for `vector_size`, this should never be demoted to a > > > warning. > > Argument of a GNU vector size attribute specifies vector size measured in > > bytes(see https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html). So > > you got right diagnostics. Both compilers with and without my changes print > > the same diagnostics for yours case. Here is a small testcase used both > > GNU and clang extensions > > > > $ cat bruno.c > > > > > > typedef __attribute__((__ext_vector_type__(8))) int vector_int8; > > typedef __attribute__((__ext_vector_type__(8))) unsigned char vector_uchar8; > > > > typedef __attribute__((vector_size(8))) int vector_int8n; > > typedef __attribute__((vector_size(8))) unsigned char vector_uchar8n; > > > > vector_int8 vi8; > > vector_uchar8 vuc8; > > vector_int8n vi8n; > > vector_uchar8n vuc8n; > > > > int foo() { > > vi8 = vi8 << vuc8; > > vi8n = vi8n << vuc8n; > > > > $ clang -c bruno.c -Wno-error-vec-elem-size > > > > > > bruno.c:13:13: warning: vector operands do not have the same elements sizes > > ('vector_int8' (vector of 8 'int' values) and 'vector_uchar8' (vector of 8 > > 'unsigned char' values)) [-Wvec-elem-size] > > vi8 = vi8 << vuc8; > > ~~~ ^ > > bruno.c:14:15: error: vector operands do not have the same number of > > elements ('vector_int8n' (vector of 2 'int' values) and 'vector_uchar8n' > > (vector of 8 'unsigned char' values)) > > vi8n = vi8n << vuc8n; > > > > The compiler without the changes prints the second error only > > (bruno.c:14:15). > What actually concerns me here is the following: if you invoke `clang -c > bruno.c -Wvec-elem-size`, will that override the `error: vector operands do > not have the same number of elements ` message for `vector_size` typed > vectors? If so, I don't think this is right. No, this will not override the error because these diagnostics use independent conditions. The option vec-elem-size is used only for con
Re: [PATCH] D21678: Fix For pr28288 - Error message in shift of vector values
I'll fix this. Vladimir --- From: *Akira Hatanaka* Date: Fri, Sep 2, 2016 at 3:00 AM Subject: Re: [PATCH] D21678: Fix For pr28288 - Error message in shift of vector values To: vladimi...@gmail.com, ulrich.weig...@de.ibm.com, amjad.ab...@intel.com, guy.ben...@intel.com, aaron.ball...@gmail.com Cc: ahata...@gmail.com, andreybokha...@gmail.com, anastasia.stul...@arm.com, dmitry.poluk...@gmail.com, cfe-commits@lists.llvm.org ahatanak added a subscriber: ahatanak. ahatanak added a comment. This patch causes clang to error out on the following code, which used to compile fine: $ cat f2.c typedef __attribute__((__ext_vector_type__(8))) unsigned short vector_ushort8; vector_ushort8 foo1(void) { return 1 << (vector_ushort8){7,6,5,4,3,2,1,0}; } $ clang f2.c -c clang used to transform the scaler operand to a vector operand (similar to the way gcc's vector is handled) when compiling for normal c/c++ (but printed an error message when compiling for opencl), but this patch dropped the check for LangOpts added in r230464 and changed that behavior. I don't think this was intentional? Repository: rL LLVM https://reviews.llvm.org/D21678 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D24467: Fix an error after D21678
vbyakovlcl created this revision. vbyakovlcl added reviewers: ahatanak, aaron.ballman. vbyakovlcl added subscribers: andreybokhanko, cfe-commits. vbyakovlcl set the repository for this revision to rL LLVM. vbyakovlcl changed the visibility of this Differential Revision from "Public (No Login Required)" to "All Users". Herald added a subscriber: aemerson. This fixes an error and gcc incompatibilities in vector shifts reported by Akira Hatanaka -- From: Akira Hatanaka Date: Fri, Sep 2, 2016 at 3:00 AM Subject: Re: [PATCH] D21678: Fix For pr28288 - Error message in shift of vector values To: vladimi...@gmail.com, ulrich.weig...@de.ibm.com, amjad.ab...@intel.com, guy.ben...@intel.com, aaron.ball...@gmail.com Cc: ahata...@gmail.com, andreybokha...@gmail.com, anastasia.stul...@arm.com, dmitry.poluk...@gmail.com, cfe-commits@lists.llvm.org ahatanak added a subscriber: ahatanak. ahatanak added a comment. This patch causes clang to error out on the following code, which used to compile fine: $ cat f2.c typedef __attribute__((__ext_vector_type__(8))) unsigned short vector_ushort8; vector_ushort8 foo1(void) { return 1 << (vector_ushort8){7,6,5,4,3,2,1,0}; } $ clang f2.c -c clang used to transform the scaler operand to a vector operand (similar to the way gcc's vector is handled) when compiling for normal c/c++ (but printed an error message when compiling for opencl), but this patch dropped the check for LangOpts added in r230464 and changed that behavior. I don't think this was intentional? Repository: rL LLVM https://reviews.llvm.org/D21678 Repository: rL LLVM https://reviews.llvm.org/D24467 Files: llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td llvm/tools/clang/lib/Sema/SemaExpr.cpp llvm/tools/clang/test/Sema/vecshift.c Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp === --- llvm/tools/clang/lib/Sema/SemaExpr.cpp +++ llvm/tools/clang/lib/Sema/SemaExpr.cpp @@ -8721,24 +8721,28 @@ static QualType checkVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign) { // OpenCL v1.1 s6.3.j says RHS can be a vector only if LHS is a vector. - if (!LHS.get()->getType()->isVectorType()) { + if ((S.LangOpts.OpenCL || S.LangOpts.ZVector) && + !LHS.get()->getType()->isVectorType()) { S.Diag(Loc, diag::err_shift_rhs_only_vector) << RHS.get()->getType() << LHS.get()->getType() << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); return QualType(); } if (!IsCompAssign) { -LHS = S.UsualUnaryConversions(LHS.get()); +if (S.LangOpts.OpenCL || S.LangOpts.ZVector) + LHS = S.UsualUnaryConversions(LHS.get()); +else + LHS = S.DefaultFunctionArrayLvalueConversion(LHS.get()); if (LHS.isInvalid()) return QualType(); } RHS = S.UsualUnaryConversions(RHS.get()); if (RHS.isInvalid()) return QualType(); QualType LHSType = LHS.get()->getType(); - const VectorType *LHSVecTy = LHSType->castAs(); - QualType LHSEleType = LHSVecTy->getElementType(); + const VectorType *LHSVecTy = LHSType->getAs(); + QualType LHSEleType = LHSVecTy ? LHSVecTy->getElementType() : LHSType; // Note that RHS might not be a vector. QualType RHSType = RHS.get()->getType(); @@ -8758,7 +8762,19 @@ return QualType(); } - if (RHSVecTy) { + if (!LHSVecTy) { +assert(RHSVecTy); +if (IsCompAssign) + return RHSType; +if (LHSEleType != RHSEleType) { + LHS = S.ImpCastExprToType(LHS.get(),RHSEleType, CK_IntegralCast); + LHSEleType = RHSEleType; +} +QualType VecTy = +S.Context.getExtVectorType(LHSEleType, RHSVecTy->getNumElements()); +LHS = S.ImpCastExprToType(LHS.get(), VecTy, CK_VectorSplat); +LHSType = VecTy; + } else if (RHSVecTy) { // OpenCL v1.1 s6.3.j says that for vector types, the operators // are applied component-wise. So if RHS is a vector, then ensure // that the number of elements is the same as LHS... @@ -8768,6 +8784,62 @@ << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); return QualType(); } +if (!S.LangOpts.OpenCL && !S.LangOpts.ZVector) { + const BuiltinType *LHSBT = LHSEleType->getAs(); + const BuiltinType *RHSBT = RHSEleType->getAs(); + if (LHSBT != RHSBT) { +BuiltinType::Kind LHSKind = LHSBT->getKind(); +BuiltinType::Kind RHSKind = RHSBT->getKind(); +bool DiffSizes = true; +switch (LHSKind) { +case BuiltinType::Char_S: + DiffSizes = + RHSKind != BuiltinType::Char_U && RHSKind != BuiltinType::UChar; + break; +case BuiltinType::Char_U: + DiffSizes = + RHSKind != BuiltinType::Char_S && RHSKind != BuiltinType::UChar; + break; +case BuiltinType::UChar: + Diff
Re: [PATCH] D24467: Fix an error after D21678
vbyakovlcl removed rL LLVM as the repository for this revision. vbyakovlcl changed the visibility of this Differential Revision from "All Users" to "Public (No Login Required)". vbyakovlcl updated this revision to Diff 71135. https://reviews.llvm.org/D24467 Files: llvm/tools/clang/lib/Sema/SemaExpr.cpp llvm/tools/clang/test/Sema/vecshift.c Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp === --- llvm/tools/clang/lib/Sema/SemaExpr.cpp +++ llvm/tools/clang/lib/Sema/SemaExpr.cpp @@ -8721,7 +8721,8 @@ static QualType checkVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign) { // OpenCL v1.1 s6.3.j says RHS can be a vector only if LHS is a vector. - if (!LHS.get()->getType()->isVectorType()) { + if ((S.LangOpts.OpenCL || S.LangOpts.ZVector) && + !LHS.get()->getType()->isVectorType()) { S.Diag(Loc, diag::err_shift_rhs_only_vector) << RHS.get()->getType() << LHS.get()->getType() << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); @@ -8737,8 +8738,10 @@ if (RHS.isInvalid()) return QualType(); QualType LHSType = LHS.get()->getType(); - const VectorType *LHSVecTy = LHSType->castAs(); - QualType LHSEleType = LHSVecTy->getElementType(); + // Note that LHS might be a scalar because the routine calls not only in + // OpenCL case. + const VectorType *LHSVecTy = LHSType->getAs(); + QualType LHSEleType = LHSVecTy ? LHSVecTy->getElementType() : LHSType; // Note that RHS might not be a vector. QualType RHSType = RHS.get()->getType(); @@ -8758,7 +8761,19 @@ return QualType(); } - if (RHSVecTy) { + if (!LHSVecTy) { +assert(RHSVecTy); +if (IsCompAssign) + return RHSType; +if (LHSEleType != RHSEleType) { + LHS = S.ImpCastExprToType(LHS.get(),RHSEleType, CK_IntegralCast); + LHSEleType = RHSEleType; +} +QualType VecTy = +S.Context.getExtVectorType(LHSEleType, RHSVecTy->getNumElements()); +LHS = S.ImpCastExprToType(LHS.get(), VecTy, CK_VectorSplat); +LHSType = VecTy; + } else if (RHSVecTy) { // OpenCL v1.1 s6.3.j says that for vector types, the operators // are applied component-wise. So if RHS is a vector, then ensure // that the number of elements is the same as LHS... Index: llvm/tools/clang/test/Sema/vecshift.c === --- llvm/tools/clang/test/Sema/vecshift.c +++ llvm/tools/clang/test/Sema/vecshift.c @@ -0,0 +1,80 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +typedef __attribute__((__ext_vector_type__(8))) char vector_char8; +typedef __attribute__((__ext_vector_type__(8))) short vector_short8; +typedef __attribute__((__ext_vector_type__(8))) int vector_int8; +typedef __attribute__((__ext_vector_type__(8))) unsigned char vector_uchar8; +typedef __attribute__((__ext_vector_type__(8))) unsigned short vector_ushort8; +typedef __attribute__((__ext_vector_type__(8))) unsigned int vector_uint8; +typedef __attribute__((__ext_vector_type__(4))) char vector_char4; +typedef __attribute__((__ext_vector_type__(4))) short vector_short4; +typedef __attribute__((__ext_vector_type__(4))) int vector_int4; +typedef __attribute__((__ext_vector_type__(4))) unsigned char vector_uchar4; +typedef __attribute__((__ext_vector_type__(4))) unsigned short vector_ushort4; +typedef __attribute__((__ext_vector_type__(4))) unsigned int vector_uint4; + +char c; +short s; +int i; +unsigned char uc; +unsigned short us; +unsigned int ui; +vector_char8 vc8; +vector_short8 vs8; +vector_int8 vi8; +vector_uchar8 vuc8; +vector_ushort8 vus8; +vector_uint8 vui8; +vector_char4 vc4; +vector_short4 vs4; +vector_int4 vi4; +vector_uchar4 vuc4; +vector_ushort4 vus4; +vector_uint4 vui4; + +void foo() { + vc8 = 1 << vc8; + vuc8 = 1 << vuc8; + vi8 = 1 << vi8; + vui8 = 1 << vui8; + vs8 = 1 << vs8; + vus8 = 1 << vus8; + + vc8 = c << vc8; + vuc8 = i << vuc8; + vi8 = uc << vi8; + vui8 = us << vui8; + vs8 = ui << vs8; + vus8 = 1 << vus8; + + vc8 = vc8 << vc8; + vi8 = vi8 << vuc8; + vuc8 = vuc8 << vi8; + vus8 = vus8 << vui8; + vui8 = vui8 << vs8; + + vc4 = vc4 << vc8; // expected-error {{vector operands do not have the same number of elements}} + vi4 = vi4 << vuc8; // expected-error {{vector operands do not have the same number of elements}} + vuc4 = vuc4 << vi8; // expected-error {{vector operands do not have the same number of elements}} + vus4 = vus4 << vui8; // expected-error {{vector operands do not have the same number of elements}} + vui4 = vui4 << vs8; // expected-error {{vector operands do not have the same number of elements}} + + + vc8 = vc8 << vc4; // expected-error {{vector operands do not have the same number of elements}} + vi8 = vi8 << vuc4; // expected-error {{vector operands do not have the same number of elements}} + vuc8 = vuc8 << vi4; // expected-error {{vector operands do not have the same numb
Re: [PATCH] D24467: Fix an error after D21678
vbyakovlcl added inline comments. Comment at: llvm/tools/clang/lib/Sema/SemaExpr.cpp:8733 @@ -8731,2 +8732,3 @@ if (!IsCompAssign) { -LHS = S.UsualUnaryConversions(LHS.get()); +if (S.LangOpts.OpenCL || S.LangOpts.ZVector) + LHS = S.UsualUnaryConversions(LHS.get()); ahatanak wrote: > It wasn't clear to me why we have to call > DefaultFunctionArrayLvalueConversion instead of UsualUnaryConversions. Is it > possible to come up with a test case that would fail without this change, and > if it is, can you add it to vecshift.c? I cannot remember why I did this change. Removing it doesn't cause any new fails. Comment at: llvm/tools/clang/lib/Sema/SemaExpr.cpp:8747 @@ -8742,3 +8746,3 @@ // Note that RHS might not be a vector. QualType RHSType = RHS.get()->getType(); ahatanak wrote: > We no longer error out when LHS is not a vector, so it should mention that > either the LHS or the RHS might not be a vector. I added a comment. Comment at: llvm/tools/clang/lib/Sema/SemaExpr.cpp:8787 @@ -8770,1 +8786,3 @@ } +if (!S.LangOpts.OpenCL && !S.LangOpts.ZVector) { + const BuiltinType *LHSBT = LHSEleType->getAs(); ahatanak wrote: > Is it possible to split this out to another patch? The first patch would fix > handling of (scalar << vector) and the second patch would make clang reject > vector shifts if element sizes of the LHS and RHS are different. It's not > clear whether it's correct to reject the latter case, so perhaps you can > discuss it in a separate patch? Ok. I removed this and will fail a new review after committing of this review. Comment at: llvm/tools/clang/lib/Sema/SemaExpr.cpp:8847 @@ -8774,3 +8846,3 @@ S.Context.getExtVectorType(RHSEleType, LHSVecTy->getNumElements()); RHS = S.ImpCastExprToType(RHS.get(), VecTy, CK_VectorSplat); } ahatanak wrote: > When the LHS is a scalar, we check the type of the LHS and the element type > of the RHS, and if necessary, cast the LHS to the element type of the RHS. > What's the reason we don't do the same here? No need, because CodeGen inserts a conversion. define <8 x i16> @foo1(<8 x i16> %n, i32 %m) #0 { entry: %n.addr = alloca <8 x i16>, align 16 %m.addr = alloca i32, align 4 store <8 x i16> %n, <8 x i16>* %n.addr, align 16 store i32 %m, i32* %m.addr, align 4 %0 = load <8 x i16>, <8 x i16>* %n.addr, align 16 %1 = load i32, i32* %m.addr, align 4 %splat.splatinsert = insertelement <8 x i32> undef, i32 %1, i32 0 %splat.splat = shufflevector <8 x i32> %splat.splatinsert, <8 x i32> undef, <8 x i32> zeroinitializer %sh_prom = trunc <8 x i32> %splat.splat to <8 x i16> %shl = shl <8 x i16> %0, %sh_prom ret <8 x i16> %shl We need insert a conversion of scalar LHS to the RHS element type because we must return a vector of the RHS type. https://reviews.llvm.org/D24467 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24467: Fix an error after D21678
vbyakovlcl added inline comments. Comment at: llvm/tools/clang/lib/Sema/SemaExpr.cpp:8790 @@ -8774,3 +8789,3 @@ S.Context.getExtVectorType(RHSEleType, LHSVecTy->getNumElements()); RHS = S.ImpCastExprToType(RHS.get(), VecTy, CK_VectorSplat); } ahatanak wrote: > OK. So the rule is that the type of the scalar operand is normally converted > to the vector element type of the other operand before being transformed to a > vector, but we don't have to do this when it's used as the RHS (shift amount) > because IRGen generates the correct IR without the conversion? Yes. I think a CodeGen test should be added for checking of IR correctness. Comment at: llvm/tools/clang/test/Sema/vecshift.c:56 @@ +55,3 @@ + + vc4 = vc4 << vc8; // expected-error {{vector operands do not have the same number of elements}} + vi4 = vi4 << vuc8; // expected-error {{vector operands do not have the same number of elements}} ahatanak wrote: > I don't think this patch was necessary to have clang print diagnostic "vector > operands do not have the same number of elements"? If that's the case, I > think it's better to add these lines in a separate commit. Do you propose to delete lines with this diagnostic? https://reviews.llvm.org/D24467 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24467: Fix an error after D21678
vbyakovlcl updated this revision to Diff 71498. https://reviews.llvm.org/D24467 Files: llvm/tools/clang/lib/Sema/SemaExpr.cpp llvm/tools/clang/test/CodeGen/vecshift.c llvm/tools/clang/test/Sema/vecshift.c Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp === --- llvm/tools/clang/lib/Sema/SemaExpr.cpp +++ llvm/tools/clang/lib/Sema/SemaExpr.cpp @@ -8721,7 +8721,8 @@ static QualType checkVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign) { // OpenCL v1.1 s6.3.j says RHS can be a vector only if LHS is a vector. - if (!LHS.get()->getType()->isVectorType()) { + if ((S.LangOpts.OpenCL || S.LangOpts.ZVector) && + !LHS.get()->getType()->isVectorType()) { S.Diag(Loc, diag::err_shift_rhs_only_vector) << RHS.get()->getType() << LHS.get()->getType() << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); @@ -8737,15 +8738,17 @@ if (RHS.isInvalid()) return QualType(); QualType LHSType = LHS.get()->getType(); - const VectorType *LHSVecTy = LHSType->castAs(); - QualType LHSEleType = LHSVecTy->getElementType(); + // Note that LHS might be a scalar because the routine calls not only in + // OpenCL case. + const VectorType *LHSVecTy = LHSType->getAs(); + QualType LHSEleType = LHSVecTy ? LHSVecTy->getElementType() : LHSType; // Note that RHS might not be a vector. QualType RHSType = RHS.get()->getType(); const VectorType *RHSVecTy = RHSType->getAs(); QualType RHSEleType = RHSVecTy ? RHSVecTy->getElementType() : RHSType; - // OpenCL v1.1 s6.3.j says that the operands need to be integers. + // The operands need to be integers. if (!LHSEleType->isIntegerType()) { S.Diag(Loc, diag::err_typecheck_expect_int) << LHS.get()->getType() << LHS.get()->getSourceRange(); @@ -8758,7 +8761,19 @@ return QualType(); } - if (RHSVecTy) { + if (!LHSVecTy) { +assert(RHSVecTy); +if (IsCompAssign) + return RHSType; +if (LHSEleType != RHSEleType) { + LHS = S.ImpCastExprToType(LHS.get(),RHSEleType, CK_IntegralCast); + LHSEleType = RHSEleType; +} +QualType VecTy = +S.Context.getExtVectorType(LHSEleType, RHSVecTy->getNumElements()); +LHS = S.ImpCastExprToType(LHS.get(), VecTy, CK_VectorSplat); +LHSType = VecTy; + } else if (RHSVecTy) { // OpenCL v1.1 s6.3.j says that for vector types, the operators // are applied component-wise. So if RHS is a vector, then ensure // that the number of elements is the same as LHS... Index: llvm/tools/clang/test/CodeGen/vecshift.c === --- llvm/tools/clang/test/CodeGen/vecshift.c +++ llvm/tools/clang/test/CodeGen/vecshift.c @@ -0,0 +1,146 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s + +typedef __attribute__((__ext_vector_type__(8))) char vector_char8; +typedef __attribute__((__ext_vector_type__(8))) short vector_short8; +typedef __attribute__((__ext_vector_type__(8))) int vector_int8; +typedef __attribute__((__ext_vector_type__(8))) unsigned char vector_uchar8; +typedef __attribute__((__ext_vector_type__(8))) unsigned short vector_ushort8; +typedef __attribute__((__ext_vector_type__(8))) unsigned int vector_uint8; +typedef __attribute__((__ext_vector_type__(4))) char vector_char4; +typedef __attribute__((__ext_vector_type__(4))) short vector_short4; +typedef __attribute__((__ext_vector_type__(4))) int vector_int4; +typedef __attribute__((__ext_vector_type__(4))) unsigned char vector_uchar4; +typedef __attribute__((__ext_vector_type__(4))) unsigned short vector_ushort4; +typedef __attribute__((__ext_vector_type__(4))) unsigned int vector_uint4; + +char c; +short s; +int i; +unsigned char uc; +unsigned short us; +unsigned int ui; +vector_char8 vc8; +vector_short8 vs8; +vector_int8 vi8; +vector_uchar8 vuc8; +vector_ushort8 vus8; +vector_uint8 vui8; +vector_char4 vc4; +vector_short4 vs4; +vector_int4 vi4; +vector_uchar4 vuc4; +vector_ushort4 vus4; +vector_uint4 vui4; + +void foo() { + vc8 = 1 << vc8; +// CHECK: [[t0:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}}, align 8 +// CHECK: shl <8 x i8> , [[t0]] + vuc8 = 1 << vuc8; +// CHECK: [[t1:%.+]] = load <8 x i8>, <8 x i8>* @vuc8, align 8 +// CHECK: shl <8 x i8> , [[t1]] + vi8 = 1 << vi8; +// CHECK: [[t2:%.+]] = load <8 x i32>, <8 x i32>* @vi8, align 32 +// CHECK: shl <8 x i32> , [[t2]] + vui8 = 1 << vui8; +// CHECK: [[t3:%.+]] = load <8 x i32>, <8 x i32>* @vui8, align 32 +// CHECK: shl <8 x i32> , [[t3]] + vs8 = 1 << vs8; +// CHECK: [[t4:%.+]] = load <8 x i16>, <8 x i16>* @vs8, align 16 +// CHECK: shl <8 x i16> , [[t4]] + vus8 = 1 << vus8; +// CHECK: [[t5:%.+]] = load <8 x i16>, <8 x i16>* @vus8, align 16 +// CHECK: shl <8 x i16> , [[t5]] + + vc8 = c << vc8; +// CHECK: [[t6:%.+]] = load i8, i8* @c, align 1 +// CHECK: [[splat_splatinsert:%.+]] = insertelement <8 x i8> undef, i8 [[t6]], i32 0 +// CHEC
Re: [PATCH] D24467: Fix an error after D21678
vbyakovlcl added inline comments. Comment at: llvm/tools/clang/test/CodeGen/vecshift.c:43 @@ +42,3 @@ + vi8 = 1 << vi8; +// CHECK: [[t2:%.+]] = load <8 x i32>, <8 x i32>* @vi8, align 32 +// CHECK: shl <8 x i32> , [[t2]] ahatanak wrote: > This test fails on my machine because MaxVectorAlign is 128 (16B) for darwin. > Maybe you can remove the alignment checks or add a triple to the RUN line? Done https://reviews.llvm.org/D24467 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24467: Fix an error after D21678
vbyakovlcl updated this revision to Diff 71545. https://reviews.llvm.org/D24467 Files: llvm/tools/clang/lib/Sema/SemaExpr.cpp llvm/tools/clang/test/CodeGen/vecshift.c llvm/tools/clang/test/Sema/vecshift.c Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp === --- llvm/tools/clang/lib/Sema/SemaExpr.cpp +++ llvm/tools/clang/lib/Sema/SemaExpr.cpp @@ -8721,7 +8721,8 @@ static QualType checkVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign) { // OpenCL v1.1 s6.3.j says RHS can be a vector only if LHS is a vector. - if (!LHS.get()->getType()->isVectorType()) { + if ((S.LangOpts.OpenCL || S.LangOpts.ZVector) && + !LHS.get()->getType()->isVectorType()) { S.Diag(Loc, diag::err_shift_rhs_only_vector) << RHS.get()->getType() << LHS.get()->getType() << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); @@ -8737,15 +8738,17 @@ if (RHS.isInvalid()) return QualType(); QualType LHSType = LHS.get()->getType(); - const VectorType *LHSVecTy = LHSType->castAs(); - QualType LHSEleType = LHSVecTy->getElementType(); + // Note that LHS might be a scalar because the routine calls not only in + // OpenCL case. + const VectorType *LHSVecTy = LHSType->getAs(); + QualType LHSEleType = LHSVecTy ? LHSVecTy->getElementType() : LHSType; // Note that RHS might not be a vector. QualType RHSType = RHS.get()->getType(); const VectorType *RHSVecTy = RHSType->getAs(); QualType RHSEleType = RHSVecTy ? RHSVecTy->getElementType() : RHSType; - // OpenCL v1.1 s6.3.j says that the operands need to be integers. + // The operands need to be integers. if (!LHSEleType->isIntegerType()) { S.Diag(Loc, diag::err_typecheck_expect_int) << LHS.get()->getType() << LHS.get()->getSourceRange(); @@ -8758,7 +8761,19 @@ return QualType(); } - if (RHSVecTy) { + if (!LHSVecTy) { +assert(RHSVecTy); +if (IsCompAssign) + return RHSType; +if (LHSEleType != RHSEleType) { + LHS = S.ImpCastExprToType(LHS.get(),RHSEleType, CK_IntegralCast); + LHSEleType = RHSEleType; +} +QualType VecTy = +S.Context.getExtVectorType(LHSEleType, RHSVecTy->getNumElements()); +LHS = S.ImpCastExprToType(LHS.get(), VecTy, CK_VectorSplat); +LHSType = VecTy; + } else if (RHSVecTy) { // OpenCL v1.1 s6.3.j says that for vector types, the operators // are applied component-wise. So if RHS is a vector, then ensure // that the number of elements is the same as LHS... Index: llvm/tools/clang/test/CodeGen/vecshift.c === --- llvm/tools/clang/test/CodeGen/vecshift.c +++ llvm/tools/clang/test/CodeGen/vecshift.c @@ -0,0 +1,146 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s + +typedef __attribute__((__ext_vector_type__(8))) char vector_char8; +typedef __attribute__((__ext_vector_type__(8))) short vector_short8; +typedef __attribute__((__ext_vector_type__(8))) int vector_int8; +typedef __attribute__((__ext_vector_type__(8))) unsigned char vector_uchar8; +typedef __attribute__((__ext_vector_type__(8))) unsigned short vector_ushort8; +typedef __attribute__((__ext_vector_type__(8))) unsigned int vector_uint8; +typedef __attribute__((__ext_vector_type__(4))) char vector_char4; +typedef __attribute__((__ext_vector_type__(4))) short vector_short4; +typedef __attribute__((__ext_vector_type__(4))) int vector_int4; +typedef __attribute__((__ext_vector_type__(4))) unsigned char vector_uchar4; +typedef __attribute__((__ext_vector_type__(4))) unsigned short vector_ushort4; +typedef __attribute__((__ext_vector_type__(4))) unsigned int vector_uint4; + +char c; +short s; +int i; +unsigned char uc; +unsigned short us; +unsigned int ui; +vector_char8 vc8; +vector_short8 vs8; +vector_int8 vi8; +vector_uchar8 vuc8; +vector_ushort8 vus8; +vector_uint8 vui8; +vector_char4 vc4; +vector_short4 vs4; +vector_int4 vi4; +vector_uchar4 vuc4; +vector_ushort4 vus4; +vector_uint4 vui4; + +void foo() { + vc8 = 1 << vc8; +// CHECK: [[t0:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}}, +// CHECK: shl <8 x i8> , [[t0]] + vuc8 = 1 << vuc8; +// CHECK: [[t1:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}}, +// CHECK: shl <8 x i8> , [[t1]] + vi8 = 1 << vi8; +// CHECK: [[t2:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}}, +// CHECK: shl <8 x i32> , [[t2]] + vui8 = 1 << vui8; +// CHECK: [[t3:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}}, +// CHECK: shl <8 x i32> , [[t3]] + vs8 = 1 << vs8; +// CHECK: [[t4:%.+]] = load <8 x i16>, <8 x i16>* {{@.+}}, +// CHECK: shl <8 x i16> , [[t4]] + vus8 = 1 << vus8; +// CHECK: [[t5:%.+]] = load <8 x i16>, <8 x i16>* {{@.+}}, +// CHECK: shl <8 x i16> , [[t5]] + + vc8 = c << vc8; +// CHECK: [[t6:%.+]] = load i8, i8* @c, +// CHECK: [[splat_splatinsert:%.+]] = insertelement <8 x i8> undef, i8 [[t6]], i32 0 +// CHECK: [[splat_splat:%.+]] = shufflevector <8 x i8>
[PATCH] D24669: {Sema] Gcc compatibility of vector shift.
vbyakovlcl created this revision. vbyakovlcl added reviewers: aaron.ballman, ahatanak. vbyakovlcl added a subscriber: cfe-commits. vbyakovlcl set the repository for this revision to rL LLVM. Gcc prints error if elements of left and right parts of a shift have different sizes. This patch is provided the GCC compatibility. Repository: rL LLVM https://reviews.llvm.org/D24669 Files: llvm/tools/clang/include/clang/Basic/DiagnosticGroups.td llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td llvm/tools/clang/lib/Sema/SemaExpr.cpp llvm/tools/clang/test/Sema/vecshift.c Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp === --- llvm/tools/clang/lib/Sema/SemaExpr.cpp +++ llvm/tools/clang/lib/Sema/SemaExpr.cpp @@ -8784,6 +8784,65 @@ << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); return QualType(); } +if (!S.LangOpts.OpenCL && !S.LangOpts.ZVector) { + const BuiltinType *LHSBT = LHSEleType->getAs(); + const BuiltinType *RHSBT = RHSEleType->getAs(); + if (LHSBT != RHSBT) { +BuiltinType::Kind LHSKind = LHSBT->getKind(); +BuiltinType::Kind RHSKind = RHSBT->getKind(); +bool DiffSizes = true; +switch (LHSKind) { +case BuiltinType::Char_S: + DiffSizes = + RHSKind != BuiltinType::Char_U && RHSKind != BuiltinType::UChar; + break; +case BuiltinType::Char_U: + DiffSizes = + RHSKind != BuiltinType::Char_S && RHSKind != BuiltinType::UChar; + break; +case BuiltinType::UChar: + DiffSizes = + RHSKind != BuiltinType::Char_U && RHSKind != BuiltinType::Char_S; + break; +case BuiltinType::Short: + DiffSizes = RHSKind != BuiltinType::UShort; + break; +case BuiltinType::UShort: + DiffSizes = RHSKind != BuiltinType::Short; + break; +case BuiltinType::Int: + DiffSizes = RHSKind != BuiltinType::UInt; + break; +case BuiltinType::UInt: + DiffSizes = RHSKind != BuiltinType::Int; + break; +case BuiltinType::Long: + DiffSizes = RHSKind != BuiltinType::ULong; + break; +case BuiltinType::ULong: + DiffSizes = RHSKind != BuiltinType::Long; + break; +case BuiltinType::LongLong: + DiffSizes = RHSKind != BuiltinType::ULongLong; + break; +case BuiltinType::ULongLong: + DiffSizes = RHSKind != BuiltinType::LongLong; + break; +default: + DiffSizes = true; + break; +} +if (DiffSizes) { + S.Diag(Loc, diag::warn_typecheck_vector_element_sizes_not_equal) + << LHS.get()->getType() << RHS.get()->getType() + << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + if (S.Diags.getDiagnosticLevel( + diag::warn_typecheck_vector_element_sizes_not_equal, Loc) == + DiagnosticsEngine::Level::Error) +return QualType(); +} + } +} } else { // ...else expand RHS to match the number of elements in LHS. QualType VecTy = Index: llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td === --- llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -2301,6 +2301,9 @@ "cannot convert between vector and non-scalar values (%0 and %1)">; def err_typecheck_vector_lengths_not_equal : Error< "vector operands do not have the same number of elements (%0 and %1)">; +def warn_typecheck_vector_element_sizes_not_equal : Warning< + "vector operands do not have the same elements sizes (%0 and %1)">, + InGroup, DefaultIgnore; def err_ext_vector_component_exceeds_length : Error< "vector component access exceeds type %0">; def err_ext_vector_component_name_illegal : Error< Index: llvm/tools/clang/include/clang/Basic/DiagnosticGroups.td === --- llvm/tools/clang/include/clang/Basic/DiagnosticGroups.td +++ llvm/tools/clang/include/clang/Basic/DiagnosticGroups.td @@ -519,6 +519,7 @@ def ZeroLengthArray : DiagGroup<"zero-length-array">; def GNUZeroLineDirective : DiagGroup<"gnu-zero-line-directive">; def GNUZeroVariadicMacroArguments : DiagGroup<"gnu-zero-variadic-macro-arguments">; +def GNUVecElemSize : DiagGroup<"gnu-vec-elem-size">; def Fallback : DiagGroup<"fallback">; // This covers both the deprecated case (in C++98) @@ -758,7 +759,8 @@ GNUStringLiteralOperatorTemplate, GNUUnionCast, GNUVariableSizedTypeNotAtEnd, ZeroLengthArray, GNUZeroLineDirective, -GNUZeroVariadicMacroArguments]>; +GNU
r286224 - Test commit of vbyakovl.
Author: vbyakovl Date: Tue Nov 8 04:32:10 2016 New Revision: 286224 URL: http://llvm.org/viewvc/llvm-project?rev=286224&view=rev Log: Test commit of vbyakovl. Modified: cfe/trunk/lib/Sema/SemaType.cpp Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=286224&r1=286223&r2=286224&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Tue Nov 8 04:32:10 2016 @@ -1128,7 +1128,7 @@ TypeResult Sema::actOnObjCTypeArgsAndPro ActualTypeArgInfos.clear(); break; } - + assert(TypeArgInfo && "No type source info?"); ActualTypeArgInfos.push_back(TypeArgInfo); } @@ -1145,7 +1145,7 @@ TypeResult Sema::actOnObjCTypeArgsAndPro if (Result == T) return BaseType; - + // Create source information for this type. TypeSourceInfo *ResultTInfo = Context.CreateTypeSourceInfo(Result); TypeLoc ResultTL = ResultTInfo->getTypeLoc(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21678: Fix For pr28288 - Error message in shift of vector values
vbyakovl added a comment. Someone, please review this. https://reviews.llvm.org/D21678 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21678: Fix For pr28288 - Error message in shift of vector values
vbyakovl set the repository for this revision to rL LLVM. vbyakovl updated this revision to Diff 67140. Repository: rL LLVM https://reviews.llvm.org/D21678 Files: llvm/tools/clang/lib/Sema/SemaExpr.cpp llvm/tools/clang/test/Sema/shift.c Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp === --- llvm/tools/clang/lib/Sema/SemaExpr.cpp +++ llvm/tools/clang/lib/Sema/SemaExpr.cpp @@ -8592,11 +8592,10 @@ << RHS.get()->getSourceRange(); } -/// \brief Return the resulting type when an OpenCL vector is shifted +/// \brief Return the resulting type when a vector is shifted ///by a scalar or vector shift amount. -static QualType checkOpenCLVectorShift(Sema &S, - ExprResult &LHS, ExprResult &RHS, - SourceLocation Loc, bool IsCompAssign) { +static QualType checkVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS, + SourceLocation Loc, bool IsCompAssign) { // OpenCL v1.1 s6.3.j says RHS can be a vector only if LHS is a vector. if (!LHS.get()->getType()->isVectorType()) { S.Diag(Loc, diag::err_shift_rhs_only_vector) @@ -8664,23 +8663,18 @@ // Vector shifts promote their scalar inputs to vector type. if (LHS.get()->getType()->isVectorType() || RHS.get()->getType()->isVectorType()) { -if (LangOpts.OpenCL) - return checkOpenCLVectorShift(*this, LHS, RHS, Loc, IsCompAssign); if (LangOpts.ZVector) { // The shift operators for the z vector extensions work basically - // like OpenCL shifts, except that neither the LHS nor the RHS is + // like general shifts, except that neither the LHS nor the RHS is // allowed to be a "vector bool". if (auto LHSVecType = LHS.get()->getType()->getAs()) if (LHSVecType->getVectorKind() == VectorType::AltiVecBool) return InvalidOperands(Loc, LHS, RHS); if (auto RHSVecType = RHS.get()->getType()->getAs()) if (RHSVecType->getVectorKind() == VectorType::AltiVecBool) return InvalidOperands(Loc, LHS, RHS); - return checkOpenCLVectorShift(*this, LHS, RHS, Loc, IsCompAssign); } -return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign, - /*AllowBothBool*/true, - /*AllowBoolConversions*/false); +return checkVectorShift(*this, LHS, RHS, Loc, IsCompAssign); } // Shifts don't perform usual arithmetic conversions, they just do integer Index: llvm/tools/clang/test/Sema/shift.c === --- llvm/tools/clang/test/Sema/shift.c +++ llvm/tools/clang/test/Sema/shift.c @@ -67,3 +67,14 @@ (void) (x >> 80); // no-warning (void) (x >> 80); // expected-warning {{shift count >= width of type}} } + +typedef unsigned vec16 __attribute__((vector_size(16))); +typedef unsigned vec8 __attribute__((vector_size(8))); + +void vect_shift_1(vec16 *x) { *x = *x << 4; } + +void vect_shift_2(vec16 *x, vec16 y) { *x = *x << y; } + +void vect_shift_3(vec16 *x, vec8 y) { + *x = *x << y; // expected-error {{vector operands do not have the same number of elements}} +} Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp === --- llvm/tools/clang/lib/Sema/SemaExpr.cpp +++ llvm/tools/clang/lib/Sema/SemaExpr.cpp @@ -8592,11 +8592,10 @@ << RHS.get()->getSourceRange(); } -/// \brief Return the resulting type when an OpenCL vector is shifted +/// \brief Return the resulting type when a vector is shifted ///by a scalar or vector shift amount. -static QualType checkOpenCLVectorShift(Sema &S, - ExprResult &LHS, ExprResult &RHS, - SourceLocation Loc, bool IsCompAssign) { +static QualType checkVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS, + SourceLocation Loc, bool IsCompAssign) { // OpenCL v1.1 s6.3.j says RHS can be a vector only if LHS is a vector. if (!LHS.get()->getType()->isVectorType()) { S.Diag(Loc, diag::err_shift_rhs_only_vector) @@ -8664,23 +8663,18 @@ // Vector shifts promote their scalar inputs to vector type. if (LHS.get()->getType()->isVectorType() || RHS.get()->getType()->isVectorType()) { -if (LangOpts.OpenCL) - return checkOpenCLVectorShift(*this, LHS, RHS, Loc, IsCompAssign); if (LangOpts.ZVector) { // The shift operators for the z vector extensions work basically - // like OpenCL shifts, except that neither the LHS nor the RHS is + // like general shifts, except that neither the LHS nor the RHS is // allowed to be a "vector bool". if (auto LHSVecType = LHS.get()->getType()->getAs()) if (LHSVecType->getVectorKind() == VectorType::AltiVecBool) return InvalidOperands(Loc, LHS, RHS); if (auto RHS
Re: [PATCH] D21678: Fix For pr28288 - Error message in shift of vector values
vbyakovl added inline comments. Comment at: llvm/tools/clang/lib/Sema/SemaExpr.cpp:8597 @@ -8596,4 +8596,3 @@ ///by a scalar or vector shift amount. -static QualType checkOpenCLVectorShift(Sema &S, - ExprResult &LHS, ExprResult &RHS, - SourceLocation Loc, bool IsCompAssign) { +static QualType checkVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS, + SourceLocation Loc, bool IsCompAssign) { aaron.ballman wrote: > Why does this drop the mention of OpenCL in the function name? This routine has common applying rather than for OpenCL only. Comment at: llvm/tools/clang/lib/Sema/SemaExpr.cpp:8638 @@ -8638,4 +8637,3 @@ if (RHSVecTy) { -// OpenCL v1.1 s6.3.j says that for vector types, the operators -// are applied component-wise. So if RHS is a vector, then ensure -// that the number of elements is the same as LHS... +// For vector types, the operators are applied component-wise. So if RHS is +// a vector, then ensure that the number of elements is the same as LHS... aaron.ballman wrote: > It's good to keep language references in the comments, so I would leave the > reference in even though this is being expanded for non-OpenCL vector types > (unless the reference is incorrect). I'll restore the language reference. Comment at: llvm/tools/clang/lib/Sema/SemaExpr.cpp:8681-8683 @@ -8680,5 +8675,3 @@ } -return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign, - /*AllowBothBool*/true, - /*AllowBoolConversions*/false); } aaron.ballman wrote: > Why is it correct to remove semantic checking for vector operands? This routine targets for checking operands of operations like plus, mul ..., but not shifts. The tests vect_shift_1 and vect_shift_2 (I added) are examples which were compiled with error. Comment at: llvm/tools/clang/test/Sema/shift.c:75 @@ +74,3 @@ +void +vect_shift_1 (vec16 *x) +{ aaron.ballman wrote: > Please clang-format the test case. Ok. Repository: rL LLVM https://reviews.llvm.org/D21678 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21678: Fix For pr28288 - Error message in shift of vector values
vbyakovl added inline comments. Comment at: llvm/tools/clang/lib/Sema/SemaExpr.cpp:8681-8683 @@ -8680,5 +8676,3 @@ } -return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign, - /*AllowBothBool*/true, - /*AllowBoolConversions*/false); } aaron.ballman wrote: > Are you saying that calling `CheckVectorOperands` was always incorrect? Or > that it's no longer required because it should be fully covered by > `checkVectorShift`? Because the two methods do considerably different > checking, and I would have expected there to be more behavioral differences > in the tests by removing the call to `CheckVectorOperands` that suggests > there are tests missing. Yes, calling CheckVectorOperands is not correct here because it compares operand types to be the same. For shift it is not true. Repository: rL LLVM https://reviews.llvm.org/D21678 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D17023: pr26544: Bitfield layout with pragma pack and attributes "packed" and "aligned
vbyakovlcl created this revision. vbyakovlcl added a reviewer: rjmccall. vbyakovlcl added subscribers: DmitryPolukhin, cfe-commits. Fix clang/gcc incompatibility of bitfields layout in the presence of pragma packed and attributes aligned and packed. http://reviews.llvm.org/D17023 Files: lib/AST/RecordLayoutBuilder.cpp test/Sema/bitfield-layout_1.c Index: lib/AST/RecordLayoutBuilder.cpp === --- lib/AST/RecordLayoutBuilder.cpp +++ lib/AST/RecordLayoutBuilder.cpp @@ -1558,10 +1558,13 @@ // But, if there's a #pragma pack in play, that takes precedent over // even the 'aligned' attribute, for non-zero-width bitfields. + unsigned MaxFieldAlignmentInBits = Context.toBits(MaxFieldAlignment); if (!MaxFieldAlignment.isZero() && FieldSize) { -unsigned MaxFieldAlignmentInBits = Context.toBits(MaxFieldAlignment); -FieldAlign = std::min(FieldAlign, MaxFieldAlignmentInBits); UnpackedFieldAlign = std::min(UnpackedFieldAlign, MaxFieldAlignmentInBits); +if (FieldPacked) + FieldAlign = UnpackedFieldAlign; +else + FieldAlign = std::min(FieldAlign, MaxFieldAlignmentInBits); } // But, ms_struct just ignores all of that in unions, even explicit @@ -1601,6 +1604,8 @@ (FieldOffset & (FieldAlign-1)) + FieldSize > TypeSize)) { FieldOffset = llvm::alignTo(FieldOffset, FieldAlign); } else if (ExplicitFieldAlign && + (MaxFieldAlignmentInBits == 0 || +ExplicitFieldAlign <= MaxFieldAlignmentInBits) && Context.getTargetInfo().useExplicitBitFieldAlignment()) { // TODO: figure it out what needs to be done on targets that don't honor // bit-field type alignment like ARM APCS ABI. @@ -1614,6 +1619,8 @@ UnpackedFieldOffset = llvm::alignTo(UnpackedFieldOffset, UnpackedFieldAlign); else if (ExplicitFieldAlign && + (MaxFieldAlignmentInBits == 0 || + ExplicitFieldAlign <= MaxFieldAlignmentInBits) && Context.getTargetInfo().useExplicitBitFieldAlignment()) UnpackedFieldOffset = llvm::alignTo(UnpackedFieldOffset, ExplicitFieldAlign); Index: test/Sema/bitfield-layout_1.c === --- test/Sema/bitfield-layout_1.c +++ test/Sema/bitfield-layout_1.c @@ -0,0 +1,202 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=i686-apple-darwin9 +// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=arm-linux-gnueabihf +// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=aarch64-linux-gnu +// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=x86_64-pc-linux-gnu +// expected-no-diagnostics + +#define CHECK_SIZE(name, size) \ + extern int name##_1[sizeof(name) == size ? 1 : -1]; + + +struct __attribute__((packed)) { + int a; + int b : 4; + int c : 32; +} s0; +CHECK_SIZE(s0,9) + +#pragma pack (1) +struct { + int a; + int b : 4; + int c : 32; +} s1; +CHECK_SIZE(s1,9) + +#pragma pack (2) +struct { + int a; + int b : 4; + int c : 32; +} s2; +CHECK_SIZE(s2,10) + +#pragma pack (2) +struct __attribute__((packed)) { + int a; + int b : 4; + int c : 32; +} s3; +CHECK_SIZE(s3,10) + +#pragma pack (4) +struct __attribute__((packed)) { + int a; + int b : 4; + int c : 32; +} s4; +CHECK_SIZE(s4,12) + +#pragma pack (16) +struct { + int a; + int __attribute__((packed)) b : 4; + int __attribute__((packed)) c : 32; +} s41; +CHECK_SIZE(s41,12) + +#pragma pack (16) +struct { + int a; + int b : 4; + int c : 32; +} s5; +CHECK_SIZE(s5,12) + +#pragma pack (1) +struct __attribute__((aligned(4))) { + int a; + int b : 4; + int c : 32; +} s6; +CHECK_SIZE(s6,12) + +#pragma pack (2) +struct { + char a; + int b : 4; + int c : 32; + char s; +} s7; +CHECK_SIZE(s7,8) + +#pragma pack (1) +struct { + char a; + int b : 4; + int c : 28; + char s; +} s8; +CHECK_SIZE(s8,6) + +#pragma pack (8) +struct { + char a; + int b : 4; + int c : 28; + char s; +} s9; +CHECK_SIZE(s9,8) + +#pragma pack (8) +struct { + char a; + char s; +} s10; +CHECK_SIZE(s10,2) + +#pragma pack(4) +struct { + char a; + int b : 4; + int c : 28; + char s1; + char s2; + char s3; +} s11; +CHECK_SIZE(s11,8) + +#pragma pack(4) +struct { + short s1; + int a1 : 17; + int a2 : 17; + int a3 : 30; + short s2; +} s12; +CHECK_SIZE(s12,12) + +#pragma pack(4) +struct { + char c1; + int i1 : 17; + int i2 : 17; + int i3 : 30; + char c2; +} s13; +CHECK_SIZE(s13,12) + +#pragma pack(2) +struct { + char a; + int s; +} s14; +CHECK_SIZE(s14,6) + +#pragma pack(4) +struct { + char a; + short s; +} s15; +CHECK_SIZE(s15,4) + +#pragma pack(2) +struct { + char a; + int b : 4; + int c : 28; + char s1; + char s2; + char s3; +} s16; +CHECK_SIZE(s16,8) + +#pragma pack (16) +struct { + int __attribute__((packed)) a; + int __attribute__((packed)) b : 4; + int __attribute__((packed)) c : 32; +} s17; +CHECK_SIZE(s17,12) + +#pragma pack (16) +struct { + int __attribu
Re: [PATCH] D18823: Implementation of VlA of GNU C++ extension
vbyakovl added a comment. @rsmith ping http://reviews.llvm.org/D18823 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D18823: Implementation of VlA of GNU C++ extension
vbyakovl created this revision. vbyakovl added a reviewer: aaron.s.wishnick. vbyakovl added subscribers: DmitryPolukhin, cfe-commits. This implements GNU C++ extension "Variable length array". This works under -std=gnu++98. http://reviews.llvm.org/D18823 Files: llvm/tools/clang/lib/CodeGen/CGClass.cpp llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp llvm/tools/clang/lib/CodeGen/CodeGenFunction.h llvm/tools/clang/lib/Sema/SemaType.cpp llvm/tools/clang/test/CodeGenCXX/vla-consruct.cpp llvm/tools/clang/test/SemaCXX/c99-variable-length-array.cpp llvm/tools/clang/test/SemaCXX/vla.cpp Index: llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp === --- llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp +++ llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp @@ -472,8 +472,8 @@ } } - if (const ConstantArrayType *arrayType -= getContext().getAsConstantArrayType(E->getType())) { + if (const ArrayType *arrayType += getContext().getAsArrayType(E->getType())) { EmitCXXAggrConstructorCall(CD, arrayType, Dest.getAddress(), E); } else { CXXCtorType Type = Ctor_Complete; Index: llvm/tools/clang/lib/CodeGen/CGClass.cpp === --- llvm/tools/clang/lib/CodeGen/CGClass.cpp +++ llvm/tools/clang/lib/CodeGen/CGClass.cpp @@ -1915,7 +1915,7 @@ /// \param zeroInitialize true if each element should be /// zero-initialized before it is constructed void CodeGenFunction::EmitCXXAggrConstructorCall( -const CXXConstructorDecl *ctor, const ConstantArrayType *arrayType, +const CXXConstructorDecl *ctor, const ArrayType *arrayType, Address arrayBegin, const CXXConstructExpr *E, bool zeroInitialize) { QualType elementType; llvm::Value *numElements = Index: llvm/tools/clang/lib/CodeGen/CodeGenFunction.h === --- llvm/tools/clang/lib/CodeGen/CodeGenFunction.h +++ llvm/tools/clang/lib/CodeGen/CodeGenFunction.h @@ -1872,7 +1872,7 @@ const CXXConstructExpr *E); void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, - const ConstantArrayType *ArrayTy, + const ArrayType *ArrayTy, Address ArrayPtr, const CXXConstructExpr *E, bool ZeroInitialization = false); Index: llvm/tools/clang/lib/Sema/SemaType.cpp === --- llvm/tools/clang/lib/Sema/SemaType.cpp +++ llvm/tools/clang/lib/Sema/SemaType.cpp @@ -2155,7 +2155,8 @@ } // If this is not C99, extwarn about VLA's and C99 array size modifiers. if (!getLangOpts().C99) { -if (T->isVariableArrayType()) { +if (T->isVariableArrayType() && +!(getLangOpts().CPlusPlus && getLangOpts().GNUMode)) { // Prohibit the use of non-POD types in VLAs. QualType BaseT = Context.getBaseElementType(T); if (!T->isDependentType() && isCompleteType(Loc, BaseT) && Index: llvm/tools/clang/test/SemaCXX/vla.cpp === --- llvm/tools/clang/test/SemaCXX/vla.cpp +++ llvm/tools/clang/test/SemaCXX/vla.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify %s +// RUN: %clang_cc1 -std=c++98 -verify %s // PR11925 int n; Index: llvm/tools/clang/test/SemaCXX/c99-variable-length-array.cpp === --- llvm/tools/clang/test/SemaCXX/c99-variable-length-array.cpp +++ llvm/tools/clang/test/SemaCXX/c99-variable-length-array.cpp @@ -1,4 +1,7 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -Wvla-extension %s +// RUN: %clang_cc1 -fsyntax-only -std=c++98 -DCPP98 -verify -Wvla-extension %s +// RUN: %clang_cc1 -fsyntax-only -std=gnu++98 -DGNU98 -verify -Wvla-extension %s + +#ifdef CPP98 struct NonPOD { NonPOD(); }; @@ -123,16 +126,20 @@ (void)new vla_type; // expected-error{{variably}} } } +#endif // CPP98 +#ifdef GNU98 namespace rdar8733881 { // rdar://8733881 static const int k_cVal3 = (int)(1000*0.2f); int f() { // Ok, fold to a constant size array as an extension. char rgch[k_cVal3] = {0}; - } + } // expected-warning{{control reaches end of non-void function}} } +#endif // GNU98 +#ifdef CPP98 namespace PR11744 { template int f(int n) { T arr[3][n]; // expected-warning 3 {{variable length arrays are a C99 feature}} @@ -161,3 +168,4 @@ func2(); } } +#endif // CPP98 Index: llvm/tools/clang/test/CodeGenCXX/vla-consruct.cpp === --- llvm/tools/clang/test/CodeGenCXX/vla-consruct.cpp +++ llvm/tools/clang/test/CodeGenCXX/vla-consruct.cpp @@ -0,0 +1,139 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcxx-exceptions -fexceptions -std=gnu++98 -O0 %s -emit-llvm -o
Re: [PATCH] D18823: Implementation of VlA of GNU C++ extension
vbyakovl updated this revision to Diff 53548. vbyakovl added a comment. Sema/SemaType.cpp: Vla works in C++ by default. An error is printed if a class has not default constructor. test/SemaCXX/c99-variable-length-array.cpp: Changes is removed test/SemaCXX/vla.cpp: changes is removed. test/CodeGenCXX/vla-consruct.cpp is added. http://reviews.llvm.org/D18823 Files: llvm/tools/clang/lib/CodeGen/CGClass.cpp llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp llvm/tools/clang/lib/CodeGen/CodeGenFunction.h llvm/tools/clang/lib/Sema/SemaType.cpp llvm/tools/clang/test/CodeGenCXX/vla-consruct.cpp llvm/tools/clang/test/SemaCXX/c99-variable-length-array.cpp llvm/tools/clang/test/SemaCXX/vla-consruct.cpp Index: llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp === --- llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp +++ llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp @@ -472,8 +472,8 @@ } } - if (const ConstantArrayType *arrayType -= getContext().getAsConstantArrayType(E->getType())) { + if (const ArrayType *arrayType += getContext().getAsArrayType(E->getType())) { EmitCXXAggrConstructorCall(CD, arrayType, Dest.getAddress(), E); } else { CXXCtorType Type = Ctor_Complete; Index: llvm/tools/clang/lib/CodeGen/CGClass.cpp === --- llvm/tools/clang/lib/CodeGen/CGClass.cpp +++ llvm/tools/clang/lib/CodeGen/CGClass.cpp @@ -1915,7 +1915,7 @@ /// \param zeroInitialize true if each element should be /// zero-initialized before it is constructed void CodeGenFunction::EmitCXXAggrConstructorCall( -const CXXConstructorDecl *ctor, const ConstantArrayType *arrayType, +const CXXConstructorDecl *ctor, const ArrayType *arrayType, Address arrayBegin, const CXXConstructExpr *E, bool zeroInitialize) { QualType elementType; llvm::Value *numElements = Index: llvm/tools/clang/lib/CodeGen/CodeGenFunction.h === --- llvm/tools/clang/lib/CodeGen/CodeGenFunction.h +++ llvm/tools/clang/lib/CodeGen/CodeGenFunction.h @@ -1872,7 +1872,7 @@ const CXXConstructExpr *E); void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, - const ConstantArrayType *ArrayTy, + const ArrayType *ArrayTy, Address ArrayPtr, const CXXConstructExpr *E, bool ZeroInitialization = false); Index: llvm/tools/clang/lib/Sema/SemaType.cpp === --- llvm/tools/clang/lib/Sema/SemaType.cpp +++ llvm/tools/clang/lib/Sema/SemaType.cpp @@ -2158,10 +2158,12 @@ if (T->isVariableArrayType()) { // Prohibit the use of non-POD types in VLAs. QualType BaseT = Context.getBaseElementType(T); + const CXXRecordDecl *RD = BaseT->getAsCXXRecordDecl(); if (!T->isDependentType() && isCompleteType(Loc, BaseT) && - !BaseT.isPODType(Context) && !BaseT->isObjCLifetimeType()) { + RD && !RD->hasDefaultConstructor() && + !BaseT->isObjCLifetimeType()) { Diag(Loc, diag::err_vla_non_pod) << BaseT; -return QualType(); + return QualType(); } // Prohibit the use of VLAs during template argument deduction. else if (isSFINAEContext()) { Index: llvm/tools/clang/test/SemaCXX/vla-consruct.cpp === --- llvm/tools/clang/test/SemaCXX/vla-consruct.cpp +++ llvm/tools/clang/test/SemaCXX/vla-consruct.cpp @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcxx-exceptions -fexceptions -O0 -verify %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcxx-exceptions -fexceptions -pedantic-errors -DPE -O0 -verify %s + +# ifndef PE +// expected-no-diagnostics +# endif + +extern "C" int printf(const char*, ...); + +static int N; +struct S { + S() __attribute__ ((nothrow)) { printf("%d: S()\n", ++N); } + ~S() __attribute__ ((nothrow)) { printf("%d: ~S()\n", N--); } + int n[17]; +}; + +void print(int n, int a, int b, int c, int d) { + printf("n=%d\n,sizeof(S)=%d\nsizeof(array_t[0][0])=%d\nsizeof(array_t[0])=%d\nsizeof(array_t)=%d\n", + n, a, b, c, d); + if (n == 2) throw(n); +} + +void test(int n) { + S array_t[n][n+1]; +# ifdef PE + // expected-error@-2 {{variable length arrays are a C99 feature}} + // expected-error@-3 {{variable length arrays are a C99 feature}} +# endif + int sizeof_S = sizeof(S); + int sizeof_array_t_0_0 = sizeof(array_t[0][0]); + int sizeof_array_t_0 = sizeof(array_t[0]); + int sizeof_array_t = sizeof(array_t); + print(n, sizeof_S, sizeof_array_t_0_0, sizeof_array_t_0, sizeof_array_t); +} + +int main() +{ + try { +test(2); + } catch(int e) { +printf("expeption %d\n", e
Re: [PATCH] D18823: Implementation of VlA of GNU C++ extension
vbyakovl updated this revision to Diff 53658. vbyakovl added a comment. Sema/SemaType.cpp: Deleted POD type and default constructor checkings. test/SemaCXX/c99-variable-length-array-cxx11.cpp: Edited dianocnics. http://reviews.llvm.org/D18823 Files: llvm/tools/clang/lib/CodeGen/CGClass.cpp llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp llvm/tools/clang/lib/CodeGen/CodeGenFunction.h llvm/tools/clang/lib/Sema/SemaType.cpp llvm/tools/clang/test/CodeGenCXX/vla-consruct.cpp llvm/tools/clang/test/SemaCXX/c99-variable-length-array-cxx11.cpp llvm/tools/clang/test/SemaCXX/c99-variable-length-array.cpp llvm/tools/clang/test/SemaCXX/vla-consruct.cpp Index: llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp === --- llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp +++ llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp @@ -472,8 +472,8 @@ } } - if (const ConstantArrayType *arrayType -= getContext().getAsConstantArrayType(E->getType())) { + if (const ArrayType *arrayType += getContext().getAsArrayType(E->getType())) { EmitCXXAggrConstructorCall(CD, arrayType, Dest.getAddress(), E); } else { CXXCtorType Type = Ctor_Complete; Index: llvm/tools/clang/lib/CodeGen/CGClass.cpp === --- llvm/tools/clang/lib/CodeGen/CGClass.cpp +++ llvm/tools/clang/lib/CodeGen/CGClass.cpp @@ -1915,7 +1915,7 @@ /// \param zeroInitialize true if each element should be /// zero-initialized before it is constructed void CodeGenFunction::EmitCXXAggrConstructorCall( -const CXXConstructorDecl *ctor, const ConstantArrayType *arrayType, +const CXXConstructorDecl *ctor, const ArrayType *arrayType, Address arrayBegin, const CXXConstructExpr *E, bool zeroInitialize) { QualType elementType; llvm::Value *numElements = Index: llvm/tools/clang/lib/CodeGen/CodeGenFunction.h === --- llvm/tools/clang/lib/CodeGen/CodeGenFunction.h +++ llvm/tools/clang/lib/CodeGen/CodeGenFunction.h @@ -1872,7 +1872,7 @@ const CXXConstructExpr *E); void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, - const ConstantArrayType *ArrayTy, + const ArrayType *ArrayTy, Address ArrayPtr, const CXXConstructExpr *E, bool ZeroInitialization = false); Index: llvm/tools/clang/lib/Sema/SemaType.cpp === --- llvm/tools/clang/lib/Sema/SemaType.cpp +++ llvm/tools/clang/lib/Sema/SemaType.cpp @@ -2156,15 +2156,8 @@ // If this is not C99, extwarn about VLA's and C99 array size modifiers. if (!getLangOpts().C99) { if (T->isVariableArrayType()) { - // Prohibit the use of non-POD types in VLAs. - QualType BaseT = Context.getBaseElementType(T); - if (!T->isDependentType() && isCompleteType(Loc, BaseT) && - !BaseT.isPODType(Context) && !BaseT->isObjCLifetimeType()) { -Diag(Loc, diag::err_vla_non_pod) << BaseT; -return QualType(); - } // Prohibit the use of VLAs during template argument deduction. - else if (isSFINAEContext()) { + if (isSFINAEContext()) { Diag(Loc, diag::err_vla_in_sfinae); return QualType(); } Index: llvm/tools/clang/test/SemaCXX/vla-consruct.cpp === --- llvm/tools/clang/test/SemaCXX/vla-consruct.cpp +++ llvm/tools/clang/test/SemaCXX/vla-consruct.cpp @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcxx-exceptions -fexceptions -O0 -verify %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcxx-exceptions -fexceptions -pedantic-errors -DPE -O0 -verify %s + +# ifndef PE +// expected-no-diagnostics +# endif + +extern "C" int printf(const char*, ...); + +static int N; +struct S { + S() __attribute__ ((nothrow)) { printf("%d: S()\n", ++N); } + ~S() __attribute__ ((nothrow)) { printf("%d: ~S()\n", N--); } + int n[17]; +}; + +void print(int n, int a, int b, int c, int d) { + printf("n=%d\n,sizeof(S)=%d\nsizeof(array_t[0][0])=%d\nsizeof(array_t[0])=%d\nsizeof(array_t)=%d\n", + n, a, b, c, d); + if (n == 2) throw(n); +} + +void test(int n) { + S array_t[n][n+1]; +# ifdef PE + // expected-error@-2 {{variable length arrays are a C99 feature}} + // expected-error@-3 {{variable length arrays are a C99 feature}} +# endif + int sizeof_S = sizeof(S); + int sizeof_array_t_0_0 = sizeof(array_t[0][0]); + int sizeof_array_t_0 = sizeof(array_t[0]); + int sizeof_array_t = sizeof(array_t); + print(n, sizeof_S, sizeof_array_t_0_0, sizeof_array_t_0, sizeof_array_t); +} + +int main() +{ + try { +test(2); + } catch(int e) { +printf("expeption %d\n", e); + } + try
Re: [PATCH] D18823: Implementation of VlA of GNU C++ extension
vbyakovl added a comment. Richard, now my changes are good for you? http://reviews.llvm.org/D18823 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21678: Fix For pr28288 - Error message in shift of vector values
vbyakovl updated this revision to Diff 62345. http://reviews.llvm.org/D21678 Files: llvm/tools/clang/lib/Sema/SemaExpr.cpp llvm/tools/clang/test/Sema/shift.c Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp === --- llvm/tools/clang/lib/Sema/SemaExpr.cpp +++ llvm/tools/clang/lib/Sema/SemaExpr.cpp @@ -8592,11 +8592,10 @@ << RHS.get()->getSourceRange(); } -/// \brief Return the resulting type when an OpenCL vector is shifted +/// \brief Return the resulting type when an vector is shifted ///by a scalar or vector shift amount. -static QualType checkOpenCLVectorShift(Sema &S, - ExprResult &LHS, ExprResult &RHS, - SourceLocation Loc, bool IsCompAssign) { +static QualType checkVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS, + SourceLocation Loc, bool IsCompAssign) { // OpenCL v1.1 s6.3.j says RHS can be a vector only if LHS is a vector. if (!LHS.get()->getType()->isVectorType()) { S.Diag(Loc, diag::err_shift_rhs_only_vector) @@ -8636,9 +8635,8 @@ } if (RHSVecTy) { -// OpenCL v1.1 s6.3.j says that for vector types, the operators -// are applied component-wise. So if RHS is a vector, then ensure -// that the number of elements is the same as LHS... +// For vector types, the operators are applied component-wise. So if RHS is +// a vector, then ensure that the number of elements is the same as LHS... if (RHSVecTy->getNumElements() != LHSVecTy->getNumElements()) { S.Diag(Loc, diag::err_typecheck_vector_lengths_not_equal) << LHS.get()->getType() << RHS.get()->getType() @@ -8664,23 +8662,19 @@ // Vector shifts promote their scalar inputs to vector type. if (LHS.get()->getType()->isVectorType() || RHS.get()->getType()->isVectorType()) { -if (LangOpts.OpenCL) - return checkOpenCLVectorShift(*this, LHS, RHS, Loc, IsCompAssign); if (LangOpts.ZVector) { // The shift operators for the z vector extensions work basically - // like OpenCL shifts, except that neither the LHS nor the RHS is + // like general shifts, except that neither the LHS nor the RHS is // allowed to be a "vector bool". if (auto LHSVecType = LHS.get()->getType()->getAs()) if (LHSVecType->getVectorKind() == VectorType::AltiVecBool) return InvalidOperands(Loc, LHS, RHS); if (auto RHSVecType = RHS.get()->getType()->getAs()) if (RHSVecType->getVectorKind() == VectorType::AltiVecBool) return InvalidOperands(Loc, LHS, RHS); - return checkOpenCLVectorShift(*this, LHS, RHS, Loc, IsCompAssign); + return checkVectorShift(*this, LHS, RHS, Loc, IsCompAssign); } -return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign, - /*AllowBothBool*/true, - /*AllowBoolConversions*/false); +return checkVectorShift(*this, LHS, RHS, Loc, IsCompAssign); } // Shifts don't perform usual arithmetic conversions, they just do integer Index: llvm/tools/clang/test/Sema/shift.c === --- llvm/tools/clang/test/Sema/shift.c +++ llvm/tools/clang/test/Sema/shift.c @@ -67,3 +67,24 @@ (void) (x >> 80); // no-warning (void) (x >> 80); // expected-warning {{shift count >= width of type}} } + +typedef unsigned vec16 __attribute__ ((vector_size (16))); +typedef unsigned vec8 __attribute__ ((vector_size (8))); + +void +vect_shift_1 (vec16 *x) +{ + *x = *x << 4 ; +} + +void +vect_shift_2 (vec16 *x,vec16 y) +{ + *x = *x << y ; +} + +void +vect_shift_3 (vec16 *x,vec8 y) +{ + *x = *x << y ; // expected-error {{vector operands do not have the same number of elements}} +} Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp === --- llvm/tools/clang/lib/Sema/SemaExpr.cpp +++ llvm/tools/clang/lib/Sema/SemaExpr.cpp @@ -8592,11 +8592,10 @@ << RHS.get()->getSourceRange(); } -/// \brief Return the resulting type when an OpenCL vector is shifted +/// \brief Return the resulting type when an vector is shifted ///by a scalar or vector shift amount. -static QualType checkOpenCLVectorShift(Sema &S, - ExprResult &LHS, ExprResult &RHS, - SourceLocation Loc, bool IsCompAssign) { +static QualType checkVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS, + SourceLocation Loc, bool IsCompAssign) { // OpenCL v1.1 s6.3.j says RHS can be a vector only if LHS is a vector. if (!LHS.get()->getType()->isVectorType()) { S.Diag(Loc, diag::err_shift_rhs_only_vector) @@ -8636,9 +8635,8 @@ } if (RHSVecTy) { -// OpenCL v1.1 s6.3.j says that for vector types, the operators -// are applied component-wise. So if
Re: [PATCH] D21678: Fix For pr28288 - Error message in shift of vector values
vbyakovl updated this revision to Diff 62464. http://reviews.llvm.org/D21678 Files: llvm/tools/clang/lib/Sema/SemaExpr.cpp llvm/tools/clang/test/Sema/shift.c Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp === --- llvm/tools/clang/lib/Sema/SemaExpr.cpp +++ llvm/tools/clang/lib/Sema/SemaExpr.cpp @@ -8592,11 +8592,10 @@ << RHS.get()->getSourceRange(); } -/// \brief Return the resulting type when an OpenCL vector is shifted +/// \brief Return the resulting type when a vector is shifted ///by a scalar or vector shift amount. -static QualType checkOpenCLVectorShift(Sema &S, - ExprResult &LHS, ExprResult &RHS, - SourceLocation Loc, bool IsCompAssign) { +static QualType checkVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS, + SourceLocation Loc, bool IsCompAssign) { // OpenCL v1.1 s6.3.j says RHS can be a vector only if LHS is a vector. if (!LHS.get()->getType()->isVectorType()) { S.Diag(Loc, diag::err_shift_rhs_only_vector) @@ -8636,9 +8635,8 @@ } if (RHSVecTy) { -// OpenCL v1.1 s6.3.j says that for vector types, the operators -// are applied component-wise. So if RHS is a vector, then ensure -// that the number of elements is the same as LHS... +// For vector types, the operators are applied component-wise. So if RHS is +// a vector, then ensure that the number of elements is the same as LHS... if (RHSVecTy->getNumElements() != LHSVecTy->getNumElements()) { S.Diag(Loc, diag::err_typecheck_vector_lengths_not_equal) << LHS.get()->getType() << RHS.get()->getType() @@ -8664,23 +8662,18 @@ // Vector shifts promote their scalar inputs to vector type. if (LHS.get()->getType()->isVectorType() || RHS.get()->getType()->isVectorType()) { -if (LangOpts.OpenCL) - return checkOpenCLVectorShift(*this, LHS, RHS, Loc, IsCompAssign); if (LangOpts.ZVector) { // The shift operators for the z vector extensions work basically - // like OpenCL shifts, except that neither the LHS nor the RHS is + // like general shifts, except that neither the LHS nor the RHS is // allowed to be a "vector bool". if (auto LHSVecType = LHS.get()->getType()->getAs()) if (LHSVecType->getVectorKind() == VectorType::AltiVecBool) return InvalidOperands(Loc, LHS, RHS); if (auto RHSVecType = RHS.get()->getType()->getAs()) if (RHSVecType->getVectorKind() == VectorType::AltiVecBool) return InvalidOperands(Loc, LHS, RHS); - return checkOpenCLVectorShift(*this, LHS, RHS, Loc, IsCompAssign); } -return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign, - /*AllowBothBool*/true, - /*AllowBoolConversions*/false); +return checkVectorShift(*this, LHS, RHS, Loc, IsCompAssign); } // Shifts don't perform usual arithmetic conversions, they just do integer Index: llvm/tools/clang/test/Sema/shift.c === --- llvm/tools/clang/test/Sema/shift.c +++ llvm/tools/clang/test/Sema/shift.c @@ -67,3 +67,24 @@ (void) (x >> 80); // no-warning (void) (x >> 80); // expected-warning {{shift count >= width of type}} } + +typedef unsigned vec16 __attribute__ ((vector_size (16))); +typedef unsigned vec8 __attribute__ ((vector_size (8))); + +void +vect_shift_1 (vec16 *x) +{ + *x = *x << 4 ; +} + +void +vect_shift_2 (vec16 *x,vec16 y) +{ + *x = *x << y ; +} + +void +vect_shift_3 (vec16 *x,vec8 y) +{ + *x = *x << y ; // expected-error {{vector operands do not have the same number of elements}} +} Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp === --- llvm/tools/clang/lib/Sema/SemaExpr.cpp +++ llvm/tools/clang/lib/Sema/SemaExpr.cpp @@ -8592,11 +8592,10 @@ << RHS.get()->getSourceRange(); } -/// \brief Return the resulting type when an OpenCL vector is shifted +/// \brief Return the resulting type when a vector is shifted ///by a scalar or vector shift amount. -static QualType checkOpenCLVectorShift(Sema &S, - ExprResult &LHS, ExprResult &RHS, - SourceLocation Loc, bool IsCompAssign) { +static QualType checkVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS, + SourceLocation Loc, bool IsCompAssign) { // OpenCL v1.1 s6.3.j says RHS can be a vector only if LHS is a vector. if (!LHS.get()->getType()->isVectorType()) { S.Diag(Loc, diag::err_shift_rhs_only_vector) @@ -8636,9 +8635,8 @@ } if (RHSVecTy) { -// OpenCL v1.1 s6.3.j says that for vector types, the operators -// are applied component-wise. So if RHS is a vector, then ensure -// that the number of elements is th
Re: [PATCH] D21678: Fix For pr28288 - Error message in shift of vector values
vbyakovl added a comment. Ping! https://reviews.llvm.org/D21678 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits