From: Richard Smith Date: Fri, 22 May 2015 01:14:39 +0000 (+0000) Subject: Fix assertion when assigning to object in OpenCL constant address space. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8ec6e8150c9ca23cc01c6b4682829f2fe6fff081;p=clang Fix assertion when assigning to object in OpenCL constant address space. Patch by John Garvin! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237983 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 097605fa25..a3be7d06c4 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -276,6 +276,7 @@ public: MLV_LValueCast, // Specialized form of MLV_InvalidExpression. MLV_IncompleteType, MLV_ConstQualified, + MLV_ConstAddrSpace, MLV_ArrayType, MLV_NoSetterProperty, MLV_MemberFunction, @@ -324,6 +325,7 @@ public: CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext CM_NoSetterProperty,// Implicit assignment to ObjC property without setter CM_ConstQualified, + CM_ConstAddrSpace, CM_ArrayType, CM_IncompleteType }; diff --git a/lib/AST/ExprClassification.cpp b/lib/AST/ExprClassification.cpp index 3073a53dab..5b320c2694 100644 --- a/lib/AST/ExprClassification.cpp +++ b/lib/AST/ExprClassification.cpp @@ -606,7 +606,7 @@ static Cl::ModifiableType IsModifiable(ASTContext &Ctx, const Expr *E, if (CT.isConstQualified()) return Cl::CM_ConstQualified; if (CT.getQualifiers().getAddressSpace() == LangAS::opencl_constant) - return Cl::CM_ConstQualified; + return Cl::CM_ConstAddrSpace; // Arrays are not modifiable, only their elements are. if (CT->isArrayType()) @@ -672,6 +672,7 @@ Expr::isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc) const { llvm_unreachable("CM_LValueCast and CL_LValue don't match"); case Cl::CM_NoSetterProperty: return MLV_NoSetterProperty; case Cl::CM_ConstQualified: return MLV_ConstQualified; + case Cl::CM_ConstAddrSpace: return MLV_ConstAddrSpace; case Cl::CM_ArrayType: return MLV_ArrayType; case Cl::CM_IncompleteType: return MLV_IncompleteType; } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 3fa05e417f..7ab269c3b6 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -9200,6 +9200,9 @@ static bool CheckForModifiableLvalue(Expr *E, SourceLocation Loc, Sema &S) { } break; + case Expr::MLV_ConstAddrSpace: + DiagnoseConstAssignment(S, E, Loc); + return true; case Expr::MLV_ArrayType: case Expr::MLV_ArrayTemporary: DiagID = diag::err_typecheck_array_not_modifiable_lvalue; diff --git a/test/Sema/invalid-assignment-constant-address-space.c b/test/Sema/invalid-assignment-constant-address-space.c new file mode 100644 index 0000000000..de2af64d00 --- /dev/null +++ b/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}} +}