r324721 - Fif for an issue when Clang permits assignment to vector/extvector elements in a const method.
Andrew V. Tischenko via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 9 01:30:42 PST 2018
Author: avt77
Date: Fri Feb 9 01:30:42 2018
New Revision: 324721
URL: http://llvm.org/viewvc/llvm-project?rev=324721&view=rev
Log:
Fif for an issue when Clang permits assignment to vector/extvector elements in a const method.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprMember.cpp
cfe/trunk/test/Sema/assign.c
cfe/trunk/test/Sema/typedef-retain.c
cfe/trunk/test/SemaCXX/err_typecheck_assign_const.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=324721&r1=324720&r2=324721&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Feb 9 01:30:42 2018
@@ -4395,8 +4395,13 @@ Sema::CreateBuiltinArraySubscriptExpr(Ex
if (VK != VK_RValue)
OK = OK_VectorComponent;
- // FIXME: need to deal with const...
ResultType = VTy->getElementType();
+ QualType BaseType = BaseExpr->getType();
+ Qualifiers BaseQuals = BaseType.getQualifiers();
+ Qualifiers MemberQuals = ResultType.getQualifiers();
+ Qualifiers Combined = BaseQuals + MemberQuals;
+ if (Combined != MemberQuals)
+ ResultType = Context.getQualifiedType(ResultType, Combined);
} else if (LHSTy->isArrayType()) {
// If we see an array that wasn't promoted by
// DefaultFunctionArrayLvalueConversion, it must be an array that
@@ -10434,8 +10439,16 @@ static void DiagnoseConstAssignment(Sema
// Static fields do not inherit constness from parents.
break;
}
- break;
- } // End MemberExpr
+ break; // End MemberExpr
+ } else if (const ArraySubscriptExpr *ASE =
+ dyn_cast<ArraySubscriptExpr>(E)) {
+ E = ASE->getBase()->IgnoreParenImpCasts();
+ continue;
+ } else if (const ExtVectorElementExpr *EVE =
+ dyn_cast<ExtVectorElementExpr>(E)) {
+ E = EVE->getBase()->IgnoreParenImpCasts();
+ continue;
+ }
break;
}
Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=324721&r1=324720&r2=324721&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Fri Feb 9 01:30:42 2018
@@ -1623,10 +1623,14 @@ static ExprResult LookupMemberExpr(Sema
else
VK = BaseExpr.get()->getValueKind();
}
+
QualType ret = CheckExtVectorComponent(S, BaseType, VK, OpLoc,
Member, MemberLoc);
if (ret.isNull())
return ExprError();
+ Qualifiers BaseQ =
+ S.Context.getCanonicalType(BaseExpr.get()->getType()).getQualifiers();
+ ret = S.Context.getQualifiedType(ret, BaseQ);
return new (S.Context)
ExtVectorElementExpr(ret, VK, BaseExpr.get(), *Member, MemberLoc);
Modified: cfe/trunk/test/Sema/assign.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/assign.c?rev=324721&r1=324720&r2=324721&view=diff
==============================================================================
--- cfe/trunk/test/Sema/assign.c (original)
+++ cfe/trunk/test/Sema/assign.c Fri Feb 9 01:30:42 2018
@@ -11,10 +11,10 @@ void test2 (const struct {int a;} *x) {
typedef int arr[10];
void test3() {
- const arr b;
- const int b2[10];
- b[4] = 1; // expected-error {{read-only variable is not assignable}}
- b2[4] = 1; // expected-error {{read-only variable is not assignable}}
+ const arr b; // expected-note {{variable 'b' declared const here}}
+ const int b2[10]; // expected-note {{variable 'b2' declared const here}}
+ b[4] = 1; // expected-error {{cannot assign to variable 'b' with const-qualified type 'const arr' (aka 'int const[10]')}}
+ b2[4] = 1; // expected-error {{cannot assign to variable 'b2' with const-qualified type 'const int [10]'}}
}
typedef struct I {
Modified: cfe/trunk/test/Sema/typedef-retain.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/typedef-retain.c?rev=324721&r1=324720&r2=324721&view=diff
==============================================================================
--- cfe/trunk/test/Sema/typedef-retain.c (original)
+++ cfe/trunk/test/Sema/typedef-retain.c Fri Feb 9 01:30:42 2018
@@ -16,8 +16,8 @@ void test2(float4 a, int4p result, int i
typedef int a[5];
void test3() {
typedef const a b;
- b r;
- r[0]=10; // expected-error {{read-only variable is not assignable}}
+ b r; // expected-note {{variable 'r' declared const here}}
+ r[0] = 10; // expected-error {{cannot assign to variable 'r' with const-qualified type 'b' (aka 'int const[5]')}}
}
int test4(const a y) {
Modified: cfe/trunk/test/SemaCXX/err_typecheck_assign_const.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/err_typecheck_assign_const.cpp?rev=324721&r1=324720&r2=324721&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/err_typecheck_assign_const.cpp (original)
+++ cfe/trunk/test/SemaCXX/err_typecheck_assign_const.cpp Fri Feb 9 01:30:42 2018
@@ -129,3 +129,23 @@ void test() {
Func &bar();
bar()() = 0; // expected-error {{read-only variable is not assignable}}
}
+
+typedef float float4 __attribute__((ext_vector_type(4)));
+struct OhNo {
+ float4 v;
+ void AssignMe() const { v.x = 1; } // expected-error {{cannot assign to non-static data member within const member function 'AssignMe'}} \
+ expected-note {{member function 'OhNo::AssignMe' is declared const here}}
+};
+
+typedef float float4_2 __attribute__((__vector_size__(16)));
+struct OhNo2 {
+ float4_2 v;
+ void AssignMe() const { v[0] = 1; } // expected-error {{cannot assign to non-static data member within const member function 'AssignMe'}} \
+ expected-note {{member function 'OhNo2::AssignMe' is declared const here}}
+};
+
+struct OhNo3 {
+ float v[4];
+ void AssignMe() const { v[0] = 1; } // expected-error {{cannot assign to non-static data member within const member function 'AssignMe'}} \
+ expected-note {{member function 'OhNo3::AssignMe' is declared const here}}
+};
More information about the cfe-commits
mailing list