]> granicus.if.org Git - clang/commitdiff
Fix assertion when assigning to object in OpenCL constant address space.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 22 May 2015 01:14:39 +0000 (01:14 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 22 May 2015 01:14:39 +0000 (01:14 +0000)
Patch by John Garvin!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237983 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
lib/AST/ExprClassification.cpp
lib/Sema/SemaExpr.cpp
test/Sema/invalid-assignment-constant-address-space.c [new file with mode: 0644]

index 097605fa25dffe04b118dc990275d79b91527ffe..a3be7d06c4b18ef052ca749bf8a86de969ccd7b1 100644 (file)
@@ -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
     };
index 3073a53dab06083d67c1d873794f1b03520e15b0..5b320c2694ab52b69ea2f08c7e4b7b97996b67a9 100644 (file)
@@ -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;
   }
index 3fa05e417ffaf73b36e6cdd68fb76016487aed1b..7ab269c3b6d5e5bd12121717cb80e1e71c6a6928 100644 (file)
@@ -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 (file)
index 0000000..de2af64
--- /dev/null
@@ -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}}
+}