summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/Sema/SemaExpr.cpp9
-rw-r--r--clang/include/clang/Basic/DiagnosticKinds.def2
-rw-r--r--clang/test/Parser/ocu_vector_components.c2
3 files changed, 13 insertions, 0 deletions
diff --git a/clang/Sema/SemaExpr.cpp b/clang/Sema/SemaExpr.cpp
index 7a4200632ce..9dfcd7d5eab 100644
--- a/clang/Sema/SemaExpr.cpp
+++ b/clang/Sema/SemaExpr.cpp
@@ -317,6 +317,11 @@ ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
} else if (const VectorType *VTy = LHSTy->getAsVectorType()) {
BaseExpr = LHSExp; // vectors: V[123]
IndexExpr = RHSExp;
+
+ // Component access limited to variables (reject vec4.rg[1]).
+ if (!isa<DeclRefExpr>(BaseExpr))
+ return Diag(LLoc, diag::err_ocuvector_component_access,
+ SourceRange(LLoc, RLoc));
// FIXME: need to deal with const...
ResultType = VTy->getElementType();
} else {
@@ -435,6 +440,10 @@ ParseMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc,
SourceRange(MemberLoc));
return new MemberExpr(BaseExpr, OpKind==tok::arrow, MemberDecl, MemberLoc);
} else if (BaseType->isOCUVectorType() && OpKind == tok::period) {
+ // Component access limited to variables (reject vec4.rg.g).
+ if (!isa<DeclRefExpr>(BaseExpr))
+ return Diag(OpLoc, diag::err_ocuvector_component_access,
+ SourceRange(MemberLoc));
QualType ret = CheckOCUVectorComponent(BaseType, OpLoc, Member, MemberLoc);
if (ret.isNull())
return true;
diff --git a/clang/include/clang/Basic/DiagnosticKinds.def b/clang/include/clang/Basic/DiagnosticKinds.def
index 1ede4fd8154..b6958540be9 100644
--- a/clang/include/clang/Basic/DiagnosticKinds.def
+++ b/clang/include/clang/Basic/DiagnosticKinds.def
@@ -449,6 +449,8 @@ DIAG(err_ocuvector_component_exceeds_length, ERROR,
"vector component access exceeds type '%0'")
DIAG(err_ocuvector_component_name_illegal, ERROR,
"illegal vector component name '%0'")
+DIAG(err_ocuvector_component_access, ERROR,
+ "vector component access limited to variables")
// Function Parameter Semantic Analysis.
DIAG(err_param_with_void_type, ERROR,
diff --git a/clang/test/Parser/ocu_vector_components.c b/clang/test/Parser/ocu_vector_components.c
index fc989329baf..26627b85e85 100644
--- a/clang/test/Parser/ocu_vector_components.c
+++ b/clang/test/Parser/ocu_vector_components.c
@@ -24,4 +24,6 @@ static void test() {
vec2.xx = vec2_2.xy; // expected-error {{vector is not assignable (contains duplicate components)}}
vec2.yx = vec2_2.xy;
vec4 = (float4){ 1,2,3,4 };
+ vec4.rg.g; // expected-error {{vector component access limited to variables}}
+ vec4.rg[1]; // expected-error {{vector component access limited to variables}}
}
OpenPOWER on IntegriCloud