[cfe-commits] r45784 - in /cfe/trunk: AST/ASTContext.cpp Sema/SemaDecl.cpp test/Sema/predefined-function.c
Steve Naroff
snaroff at apple.com
Wed Jan 9 14:43:09 PST 2008
Author: snaroff
Date: Wed Jan 9 16:43:08 2008
New Revision: 45784
URL: http://llvm.org/viewvc/llvm-project?rev=45784&view=rev
Log:
Fix ASTContext::typesAreCompatible to allow for int/enum compatibility (C99 6.7.2.2p4).
Fix Sema::MergeFunctionDecl to allow for function type compatibility (by using the predicate on ASTContext). Function types don't have to be identical to be compatible...
Modified:
cfe/trunk/AST/ASTContext.cpp
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/predefined-function.c
Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=45784&r1=45783&r2=45784&view=diff
==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Wed Jan 9 16:43:08 2008
@@ -1618,15 +1618,23 @@
if (rcanon->getTypeClass() == Type::Reference)
rcanon = cast<ReferenceType>(rcanon)->getReferenceeType();
- // If the canonical type classes don't match, they can't be compatible
+ // If the canonical type classes don't match...
if (lcanon->getTypeClass() != rcanon->getTypeClass()) {
// For Objective-C, it is possible for two types to be compatible
// when their classes don't match (when dealing with "id"). If either type
// is an interface, we defer to objcTypesAreCompatible().
if (lcanon->isObjCInterfaceType() || rcanon->isObjCInterfaceType())
return objcTypesAreCompatible(lcanon, rcanon);
+
+ // C99 6.7.2.2p4: Each enumerated type shall be compatible with char,
+ // a signed integer type, or an unsigned integer type.
+ if ((lcanon->isEnumeralType() && rcanon->isIntegralType()) ||
+ (rcanon->isEnumeralType() && lcanon->isIntegralType()))
+ return true;
+
return false;
}
+ // The canonical type classes match.
switch (lcanon->getTypeClass()) {
case Type::Pointer:
return pointerTypesAreCompatible(lcanon, rcanon);
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=45784&r1=45783&r2=45784&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Wed Jan 9 16:43:08 2008
@@ -245,7 +245,9 @@
if (OldQType.getTypePtr()->getTypeClass() == Type::FunctionNoProto &&
Old->getResultType() == New->getResultType())
return New;
- if (OldQType == NewQType)
+ // Function types need to be compatible, not identical. This handles
+ // duplicate function decls like "void f(int); void f(enum X);" properly.
+ if (Context.functionTypesAreCompatible(OldQType, NewQType))
return New;
}
Modified: cfe/trunk/test/Sema/predefined-function.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/predefined-function.c?rev=45784&r1=45783&r2=45784&view=diff
==============================================================================
--- cfe/trunk/test/Sema/predefined-function.c (original)
+++ cfe/trunk/test/Sema/predefined-function.c Wed Jan 9 16:43:08 2008
@@ -1,5 +1,9 @@
// RUN: clang -fsyntax-only -verify -pedantic %s
-
+
+char *funk(int format);
+enum Test {A=-1};
+char *funk(enum Test x);
+
int foo();
int foo()
{
More information about the cfe-commits
mailing list