diff options
author | Steve Naroff <snaroff@apple.com> | 2007-08-03 22:40:33 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2007-08-03 22:40:33 +0000 |
commit | 0104731e6258cb2b0445620d3b81c89bc7ffbfcd (patch) | |
tree | 567a069702172283cb859744c9d72e016ec0ed50 | |
parent | 9efdabc565548d2f64eebcf81a471e001f18b129 (diff) | |
download | bcm5719-llvm-0104731e6258cb2b0445620d3b81c89bc7ffbfcd.tar.gz bcm5719-llvm-0104731e6258cb2b0445620d3b81c89bc7ffbfcd.zip |
Restrict vector component access (using "." and "[]") to variables.
Chris suggested this, since it simplifies the code generator.
If this features is needed (and we don't think it is), we can revisit.
The following test case now produces an error.
[dylan:~/llvm/tools/clang] admin% cat t.c
typedef __attribute__(( ocu_vector_type(4) )) float float4;
static void test() {
float4 vec4;
vec4.rg.g;
vec4.rg[1];
}
[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang t.c
t.c:8:12: error: vector component access limited to variables
vec4.rg.g;
^~
t.c:9:12: error: vector component access limited to variables
vec4.rg[1];
^~~
2 diagnostics generated.
llvm-svn: 40795
-rw-r--r-- | clang/Sema/SemaExpr.cpp | 9 | ||||
-rw-r--r-- | clang/include/clang/Basic/DiagnosticKinds.def | 2 | ||||
-rw-r--r-- | clang/test/Parser/ocu_vector_components.c | 2 |
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}} } |