From a6b47a41429fb9bc7e8dcacc014dac37d5759a02 Mon Sep 17 00:00:00 2001 From: Nate Begeman Date: Sun, 15 Feb 2009 22:45:20 +0000 Subject: [PATCH] Don't allow taking the address of an element in an ext_vector llvm-svn: 64614 --- clang/lib/Sema/SemaExpr.cpp | 6 +++--- clang/test/Sema/expr-address-of.c | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 3143fc7aa1fa..60a1bea2f47c 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3485,10 +3485,10 @@ QualType Sema::CheckAddressOfOperand(Expr *op, SourceLocation OpLoc) { } } // Check for Apple extension for accessing vector components. - } else if (isa(op) && - cast(op)->getBase()->getType()->isVectorType()) { + } else if (isa(op) || (isa(op) && + cast(op)->getBase()->getType()->isVectorType())){ Diag(OpLoc, diag::err_typecheck_address_of) - << "vector" << op->getSourceRange(); + << "vector element" << op->getSourceRange(); return QualType(); } else if (dcl) { // C99 6.5.3.2p1 // We have an lvalue with a decl. Make sure the decl is not declared diff --git a/clang/test/Sema/expr-address-of.c b/clang/test/Sema/expr-address-of.c index 58bc540a30d5..7dd7dd67d37e 100644 --- a/clang/test/Sema/expr-address-of.c +++ b/clang/test/Sema/expr-address-of.c @@ -28,9 +28,14 @@ void foo() { void testVectorComponentAccess() { typedef float v4sf __attribute__ ((vector_size (16))); static v4sf q; - float* r = &q[0]; // expected-error {{address of vector requested}} + float* r = &q[0]; // expected-error {{address of vector element requested}} } +typedef __attribute__(( ext_vector_type(4) )) float float4; + +float *testExtVectorComponentAccess(float4 x) { + return &x.w; // expected-error {{address of vector element requested}} +} void f0() { register int *x0;