]> granicus.if.org Git - clang/commitdiff
enhance ExtVectorElementExpr to allow V->xxyy to work like (*V).xxyy
authorChris Lattner <sabre@nondot.org>
Mon, 16 Feb 2009 21:11:58 +0000 (21:11 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 16 Feb 2009 21:11:58 +0000 (21:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64667 91177308-0d34-0410-b5e6-96231b3b80d8

clang.xcodeproj/project.pbxproj
include/clang/AST/Expr.h
lib/CodeGen/CGExpr.cpp
lib/Sema/SemaExpr.cpp
test/Sema/ext_vector_components.c

index 96939c7bca7172ac51960ed58f25312c97116687..a310ff30d5899f2b83bf8bd4f3696a2927d4b4ac 100644 (file)
                35A057E00EAE2D950069249F /* RegionStore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RegionStore.cpp; path = lib/Analysis/RegionStore.cpp; sourceTree = "<group>"; };
                35A057E10EAE2D950069249F /* SVals.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SVals.cpp; path = lib/Analysis/SVals.cpp; sourceTree = "<group>"; };
                35A057E60EAE2DDD0069249F /* CacheTokens.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CacheTokens.cpp; path = Driver/CacheTokens.cpp; sourceTree = "<group>"; };
-               35A2B8610CF8FFA300E6C317 /* SemaUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = SemaUtil.h; path = lib/Sema/SemaUtil.h; sourceTree = "<group>"; tabWidth = 2; };
                35A3E7000DD3874400757F74 /* CGDebugInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGDebugInfo.cpp; path = lib/CodeGen/CGDebugInfo.cpp; sourceTree = "<group>"; tabWidth = 2; wrapsLines = 1; };
                35A3E7010DD3874400757F74 /* CGDebugInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = CGDebugInfo.h; path = lib/CodeGen/CGDebugInfo.h; sourceTree = "<group>"; tabWidth = 2; };
                35A8FCF60D9B4ADD001C2F97 /* ProgramPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ProgramPoint.h; path = clang/Analysis/ProgramPoint.h; sourceTree = "<group>"; };
                                DE67E70C0C020ECA00F66BC5 /* SemaStmt.cpp */,
                                3591853E0EFB1088000039AF /* SemaTemplate.cpp */,
                                DE67E70A0C020EC500F66BC5 /* SemaType.cpp */,
-                               35A2B8610CF8FFA300E6C317 /* SemaUtil.h */,
                        );
                        name = Sema;
                        sourceTree = "<group>";
index b7c5c8920d5a6d6d4fa2e75b92e540069198ac82..961eb21e5a09de299a6a3ccea8f07141127e2b2f 100644 (file)
@@ -2053,6 +2053,9 @@ public:
 /// vector, and may occur on the left hand side or right hand side.  For example
 /// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
 ///
+/// Note that the base may have either vector or pointer to vector type, just
+/// like a struct field reference.
+///
 class ExtVectorElementExpr : public Expr {
   Stmt *Base;
   IdentifierInfo &Accessor;
index 3e44c0079b3a796cb3eb2276bf06b69c5c7b84d7..03efbc9ad566ed3608f983e100743444f347672e 100644 (file)
@@ -257,13 +257,8 @@ RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, QualType ExprType) {
   if (LV.isPropertyRef())
     return EmitLoadOfPropertyRefLValue(LV, ExprType);
 
-  if (LV.isKVCRef())
-    return EmitLoadOfKVCRefLValue(LV, ExprType);
-
-  assert(0 && "Unknown LValue type!");
-  //an invalid RValue, but the assert will
-  //ensure that this point is never reached
-  return RValue();
+  assert(LV.isKVCRef() && "Unknown LValue type!");
+  return EmitLoadOfKVCRefLValue(LV, ExprType);
 }
 
 RValue CodeGenFunction::EmitLoadOfBitfieldLValue(LValue LV,
@@ -799,7 +794,16 @@ llvm::Constant *GenerateConstantVector(llvm::SmallVector<unsigned, 4> &Elts) {
 LValue CodeGenFunction::
 EmitExtVectorElementExpr(const ExtVectorElementExpr *E) {
   // Emit the base vector as an l-value.
-  LValue Base = EmitLValue(E->getBase());
+  LValue Base;
+
+  // ExtVectorElementExpr's base can either be a vector or pointer to vector.
+  if (const PointerType *PT = E->getBase()->getType()->getAsPointerType()) {
+    llvm::Value *Ptr = EmitScalarExpr(E->getBase());
+    Base = LValue::MakeAddr(Ptr, PT->getPointeeType().getCVRQualifiers());
+  } else {
+    assert(E->getBase()->getType()->isVectorType());
+    Base = EmitLValue(E->getBase());
+  }
 
   // Encode the element access list into a vector of unsigned indices.
   llvm::SmallVector<unsigned, 4> Indices;
index 9a44a087c721d44549d92cce9b0b0b9f9feac94f..ad4f297388ca799c1872cda3de1578a1bc2d627b 100644 (file)
@@ -1815,7 +1815,7 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
                        << &Member << BaseType);
   } 
   // Handle 'field access' to vectors, such as 'V.xx'.
-  if (BaseType->isExtVectorType() && OpKind == tok::period) {
+  if (BaseType->isExtVectorType()) {
     QualType ret = CheckExtVectorComponent(BaseType, OpLoc, Member, MemberLoc);
     if (ret.isNull())
       return ExprError();
index d827c1e075618da7d592b97e4c3511d9705065c4..ad0277baac9c4504ae9db2caaf6fd8c37ea52d54 100644 (file)
@@ -7,7 +7,7 @@ typedef __attribute__(( ext_vector_type(4) )) float float4;
 static void test() {
     float2 vec2, vec2_2;
     float3 vec3;
-    float4 vec4, vec4_2;
+    float4 vec4, vec4_2, *vec4p;
     float f;
 
     vec2.z; // expected-error {{vector component access exceeds type 'float2'}}
@@ -32,4 +32,6 @@ static void test() {
     vec4 = (float4){ 1,2,3,4 };
     vec4.xy.w; // expected-error {{vector component access exceeds type 'float2'}}
     vec4.s06; // expected-error {{vector component access exceeds type 'float4'}}
+  
+    vec4p->yz = vec4p->xy;
 }