r237983 - Fix assertion when assigning to object in OpenCL constant address space.
Richard Smith
richard-llvm at metafoo.co.uk
Thu May 21 18:14:39 PDT 2015
Author: rsmith
Date: Thu May 21 20:14:39 2015
New Revision: 237983
URL: http://llvm.org/viewvc/llvm-project?rev=237983&view=rev
Log:
Fix assertion when assigning to object in OpenCL constant address space.
Patch by John Garvin!
Added:
cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/ExprClassification.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=237983&r1=237982&r2=237983&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Thu May 21 20:14:39 2015
@@ -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
};
Modified: cfe/trunk/lib/AST/ExprClassification.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprClassification.cpp?rev=237983&r1=237982&r2=237983&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprClassification.cpp (original)
+++ cfe/trunk/lib/AST/ExprClassification.cpp Thu May 21 20:14:39 2015
@@ -606,7 +606,7 @@ static Cl::ModifiableType IsModifiable(A
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
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;
}
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=237983&r1=237982&r2=237983&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu May 21 20:14:39 2015
@@ -9200,6 +9200,9 @@ static bool CheckForModifiableLvalue(Exp
}
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;
Added: cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c?rev=237983&view=auto
==============================================================================
--- cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c (added)
+++ cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c Thu May 21 20:14:39 2015
@@ -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}}
+}
More information about the cfe-commits
mailing list