[cfe-commits] r40795 - in /cfe/trunk: Sema/SemaExpr.cpp include/clang/Basic/DiagnosticKinds.def test/Parser/ocu_vector_components.c

Steve Naroff snaroff at apple.com
Fri Aug 3 15:40:33 PDT 2007


Author: snaroff
Date: Fri Aug  3 17:40:33 2007
New Revision: 40795

URL: http://llvm.org/viewvc/llvm-project?rev=40795&view=rev
Log:
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.


Modified:
    cfe/trunk/Sema/SemaExpr.cpp
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/test/Parser/ocu_vector_components.c

Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=40795&r1=40794&r2=40795&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Fri Aug  3 17:40:33 2007
@@ -317,6 +317,11 @@
   } 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 @@
                   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;

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=40795&r1=40794&r2=40795&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Fri Aug  3 17:40:33 2007
@@ -449,6 +449,8 @@
      "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,

Modified: cfe/trunk/test/Parser/ocu_vector_components.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/ocu_vector_components.c?rev=40795&r1=40794&r2=40795&view=diff

==============================================================================
--- cfe/trunk/test/Parser/ocu_vector_components.c (original)
+++ cfe/trunk/test/Parser/ocu_vector_components.c Fri Aug  3 17:40:33 2007
@@ -24,4 +24,6 @@
     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}}
 }





More information about the cfe-commits mailing list