From 73525de7fd9bdd534382dc89a24f1f76db3e04b9 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 16 Feb 2009 21:11:58 +0000 Subject: [PATCH] enhance ExtVectorElementExpr to allow V->xxyy to work like (*V).xxyy git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64667 91177308-0d34-0410-b5e6-96231b3b80d8 --- clang.xcodeproj/project.pbxproj | 2 -- include/clang/AST/Expr.h | 3 +++ lib/CodeGen/CGExpr.cpp | 20 ++++++++++++-------- lib/Sema/SemaExpr.cpp | 2 +- test/Sema/ext_vector_components.c | 4 +++- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj index 96939c7bca..a310ff30d5 100644 --- a/clang.xcodeproj/project.pbxproj +++ b/clang.xcodeproj/project.pbxproj @@ -387,7 +387,6 @@ 35A057E00EAE2D950069249F /* RegionStore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RegionStore.cpp; path = lib/Analysis/RegionStore.cpp; sourceTree = ""; }; 35A057E10EAE2D950069249F /* SVals.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SVals.cpp; path = lib/Analysis/SVals.cpp; sourceTree = ""; }; 35A057E60EAE2DDD0069249F /* CacheTokens.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CacheTokens.cpp; path = Driver/CacheTokens.cpp; sourceTree = ""; }; - 35A2B8610CF8FFA300E6C317 /* SemaUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = SemaUtil.h; path = lib/Sema/SemaUtil.h; sourceTree = ""; tabWidth = 2; }; 35A3E7000DD3874400757F74 /* CGDebugInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGDebugInfo.cpp; path = lib/CodeGen/CGDebugInfo.cpp; sourceTree = ""; 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 = ""; tabWidth = 2; }; 35A8FCF60D9B4ADD001C2F97 /* ProgramPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ProgramPoint.h; path = clang/Analysis/ProgramPoint.h; sourceTree = ""; }; @@ -911,7 +910,6 @@ DE67E70C0C020ECA00F66BC5 /* SemaStmt.cpp */, 3591853E0EFB1088000039AF /* SemaTemplate.cpp */, DE67E70A0C020EC500F66BC5 /* SemaType.cpp */, - 35A2B8610CF8FFA300E6C317 /* SemaUtil.h */, ); name = Sema; sourceTree = ""; diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index b7c5c8920d..961eb21e5a 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -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; diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 3e44c0079b..03efbc9ad5 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -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 &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 Indices; diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 9a44a087c7..ad4f297388 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -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(); diff --git a/test/Sema/ext_vector_components.c b/test/Sema/ext_vector_components.c index d827c1e075..ad0277baac 100644 --- a/test/Sema/ext_vector_components.c +++ b/test/Sema/ext_vector_components.c @@ -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; } -- 2.40.0