(Resubmitted with Phabricator for easier reviewing.) This fixes an assertion failure in assignment if an lvalue is constant but its type is not const-qualified.
An expression may be MLV_ConstQualified either because the type is actually “const” or because it’s in the OpenCL constant address space (see ExprClassification.cpp:608). Unfortunately, isReferenceToConstCapture asserts that the type must actually be “const”, which is not necessarily true. This patch changes the assertion to what I think is intended. http://reviews.llvm.org/D9805 Files: lib/Sema/SemaExpr.cpp test/Sema/invalid-assignment-constant-address-space.c Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -8954,7 +8954,7 @@ /// 'const' due to being captured within a block? enum NonConstCaptureKind { NCCK_None, NCCK_Block, NCCK_Lambda }; static NonConstCaptureKind isReferenceToNonConstCapture(Sema &S, Expr *E) { - assert(E->isLValue() && E->getType().isConstQualified()); + assert(E->isModifiableLvalue(S.getASTContext()) == Expr::MLV_ConstQualified); E = E->IgnoreParens(); // Must be a reference to a declaration from an enclosing scope. Index: test/Sema/invalid-assignment-constant-address-space.c =================================================================== --- /dev/null +++ test/Sema/invalid-assignment-constant-address-space.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only + +#define OPENCL_CONSTANT 16776962 +int __attribute__((address_space(OPENCL_CONSTANT))) c[3] = {0}; + +void foo() { + c[0] = 1; //expected-error{{read-only variable is not assignable}} +} EMAIL PREFERENCES http://reviews.llvm.org/settings/panel/emailpreferences/
Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -8954,7 +8954,7 @@ /// 'const' due to being captured within a block? enum NonConstCaptureKind { NCCK_None, NCCK_Block, NCCK_Lambda }; static NonConstCaptureKind isReferenceToNonConstCapture(Sema &S, Expr *E) { - assert(E->isLValue() && E->getType().isConstQualified()); + assert(E->isModifiableLvalue(S.getASTContext()) == Expr::MLV_ConstQualified); E = E->IgnoreParens(); // Must be a reference to a declaration from an enclosing scope. Index: test/Sema/invalid-assignment-constant-address-space.c =================================================================== --- /dev/null +++ test/Sema/invalid-assignment-constant-address-space.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only + +#define OPENCL_CONSTANT 16776962 +int __attribute__((address_space(OPENCL_CONSTANT))) c[3] = {0}; + +void foo() { + c[0] = 1; //expected-error{{read-only variable is not assignable}} +}
_______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits