[cfe-commits] r47775 - in /cfe/trunk: Sema/SemaExpr.cpp include/clang/Basic/DiagnosticKinds.def test/Sema/expr-address-of.c
Steve Naroff
snaroff at apple.com
Fri Feb 29 15:30:25 PST 2008
Author: snaroff
Date: Fri Feb 29 17:30:25 2008
New Revision: 47775
URL: http://llvm.org/viewvc/llvm-project?rev=47775&view=rev
Log:
Fix http://llvm.org/bugs/show_bug.cgi?id=2103.
Modified:
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/trunk/test/Sema/expr-address-of.c
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=47775&r1=47774&r2=47775&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Fri Feb 29 17:30:25 2008
@@ -1718,19 +1718,29 @@
op->getSourceRange());
return QualType();
}
- } else if (dcl) {
+ } else if (MemberExpr *MemExpr = dyn_cast<MemberExpr>(op)) { // C99 6.5.3.2p1
+ if (MemExpr->getMemberDecl()->isBitField()) {
+ Diag(OpLoc, diag::err_typecheck_address_of,
+ std::string("bit-field"), op->getSourceRange());
+ return QualType();
+ }
+ // Check for Apple extension for accessing vector components.
+ } else if (isa<ArraySubscriptExpr>(op) &&
+ cast<ArraySubscriptExpr>(op)->getBase()->getType()->isVectorType()) {
+ Diag(OpLoc, diag::err_typecheck_address_of,
+ std::string("vector"), 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
// with the register storage-class specifier.
if (const VarDecl *vd = dyn_cast<VarDecl>(dcl)) {
if (vd->getStorageClass() == VarDecl::Register) {
- Diag(OpLoc, diag::err_typecheck_address_of_register,
- op->getSourceRange());
+ Diag(OpLoc, diag::err_typecheck_address_of,
+ std::string("register variable"), op->getSourceRange());
return QualType();
}
} else
assert(0 && "Unknown/unexpected decl type");
-
- // FIXME: add check for bitfields!
}
// If the operand has type "type", the result has type "pointer to type".
return Context.getPointerType(op->getType());
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=47775&r1=47774&r2=47775&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Fri Feb 29 17:30:25 2008
@@ -783,8 +783,8 @@
"illegal storage class on file-scoped variable")
DIAG(err_typecheck_sclass_func, ERROR,
"illegal storage class on function")
-DIAG(err_typecheck_address_of_register, ERROR,
- "address of register variable requested")
+DIAG(err_typecheck_address_of, ERROR,
+ "address of %0 requested")
DIAG(err_typecheck_invalid_lvalue_addrof, ERROR,
"address expression must be an lvalue or a function designator")
DIAG(err_typecheck_unary_expr, ERROR,
Modified: cfe/trunk/test/Sema/expr-address-of.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/expr-address-of.c?rev=47775&r1=47774&r2=47775&view=diff
==============================================================================
--- cfe/trunk/test/Sema/expr-address-of.c (original)
+++ cfe/trunk/test/Sema/expr-address-of.c Fri Feb 29 17:30:25 2008
@@ -1,10 +1,18 @@
// RUN: clang %s -verify -fsyntax-only
-struct entry { int value; };
+struct xx { int bitf:1; };
+
+struct entry { struct xx *whatever;
+ int value;
+ int bitf:1; };
void add_one(int *p) { (*p)++; }
void test() {
register struct entry *p;
add_one(&p->value);
+ struct entry pvalue;
+ add_one(&p->bitf); // expected-error {{address of bit-field requested}}
+ add_one(&pvalue.bitf); // expected-error {{address of bit-field requested}}
+ add_one(&p->whatever->bitf); // expected-error {{address of bit-field requested}}
}
void foo() {
@@ -17,4 +25,9 @@
int *x3 = &y[10];
}
+void testVectorComponentAccess() {
+ typedef float v4sf __attribute__ ((vector_size (16)));
+ static v4sf q;
+ float* r = &q[0]; // expected-error {{address of vector requested}}
+}
More information about the cfe-commits
mailing list