[cfe-commits] r65948 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def lib/Sema/SemaDeclObjC.cpp test/SemaObjC/class-bitfield.m
Steve Naroff
snaroff at apple.com
Tue Mar 3 06:49:37 PST 2009
Author: snaroff
Date: Tue Mar 3 08:49:36 2009
New Revision: 65948
URL: http://llvm.org/viewvc/llvm-project?rev=65948&view=rev
Log:
Fix <rdar://problem/6497608> clang does not catch ivar type mismatches in @implementation.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjC/class-bitfield.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def?rev=65948&r1=65947&r2=65948&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Tue Mar 3 08:49:36 2009
@@ -156,6 +156,8 @@
"reimplementation of class %0")
DIAG(err_conflicting_ivar_type, ERROR,
"instance variable %0 has conflicting type: %1 vs %2")
+DIAG(err_conflicting_ivar_bitwidth, ERROR,
+ "instance variable %0 has conflicting bitfield width")
DIAG(err_conflicting_ivar_name, ERROR,
"conflicting instance variable names: %0 vs %1")
DIAG(err_inconsistant_ivar_count, ERROR,
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=65948&r1=65947&r2=65948&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Mar 3 08:49:36 2009
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "Sema.h"
+#include "clang/AST/Expr.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclObjC.h"
#include "clang/Parse/DeclSpec.h"
@@ -688,20 +689,29 @@
ObjCIvarDecl* ClsIvar = *IVI;
assert (ImplIvar && "missing implementation ivar");
assert (ClsIvar && "missing class ivar");
+
+ // First, make sure the types match.
if (Context.getCanonicalType(ImplIvar->getType()) !=
Context.getCanonicalType(ClsIvar->getType())) {
Diag(ImplIvar->getLocation(), diag::err_conflicting_ivar_type)
<< ImplIvar->getIdentifier()
<< ImplIvar->getType() << ClsIvar->getType();
Diag(ClsIvar->getLocation(), diag::note_previous_definition);
- }
- // TODO: Two mismatched (unequal width) Ivar bitfields should be diagnosed
- // as error.
- else if (ImplIvar->getIdentifier() != ClsIvar->getIdentifier()) {
+ } else if (ImplIvar->isBitField() && ClsIvar->isBitField()) {
+ Expr *ImplBitWidth = ImplIvar->getBitWidth();
+ Expr *ClsBitWidth = ClsIvar->getBitWidth();
+ if (ImplBitWidth->getIntegerConstantExprValue(Context).getZExtValue() !=
+ ClsBitWidth->getIntegerConstantExprValue(Context).getZExtValue()) {
+ Diag(ImplBitWidth->getLocStart(), diag::err_conflicting_ivar_bitwidth)
+ << ImplIvar->getIdentifier();
+ Diag(ClsBitWidth->getLocStart(), diag::note_previous_definition);
+ }
+ }
+ // Make sure the names are identical.
+ if (ImplIvar->getIdentifier() != ClsIvar->getIdentifier()) {
Diag(ImplIvar->getLocation(), diag::err_conflicting_ivar_name)
<< ImplIvar->getIdentifier() << ClsIvar->getIdentifier();
Diag(ClsIvar->getLocation(), diag::note_previous_definition);
- return;
}
--numIvars;
}
Modified: cfe/trunk/test/SemaObjC/class-bitfield.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/class-bitfield.m?rev=65948&r1=65947&r2=65948&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/class-bitfield.m (original)
+++ cfe/trunk/test/SemaObjC/class-bitfield.m Tue Mar 3 08:49:36 2009
@@ -15,3 +15,23 @@
}
@end
+ at interface Base {
+ int i;
+}
+ at end
+
+ at interface WithBitfields: Base {
+ void *isa; // expected-note {{previous definition is here}}
+ unsigned a: 5;
+ signed b: 4;
+ int c: 5; // expected-note {{previous definition is here}}
+}
+ at end
+
+ at implementation WithBitfields {
+ char *isa; // expected-error {{instance variable 'isa' has conflicting type: 'char *' vs 'void *'}}
+ unsigned a: 5;
+ signed b: 4;
+ int c: 3; // expected-error {{instance variable 'c' has conflicting bitfield width}}
+}
+ at end
More information about the cfe-commits
mailing list