[cfe-commits] r46522 - in /cfe/trunk: AST/ASTContext.cpp Sema/SemaExpr.cpp test/Sema/function.c
Steve Naroff
snaroff at apple.com
Tue Jan 29 10:58:14 PST 2008
Author: snaroff
Date: Tue Jan 29 12:58:14 2008
New Revision: 46522
URL: http://llvm.org/viewvc/llvm-project?rev=46522&view=rev
Log:
Tighten up ASTContext::typesAreCompatible()...it needs to make sure the qualifiers match. The comment and C99 citation for this routine were correct...the code needed to conform to the comment/spec. This fixes the test added below.
Tightening up this routine forced tweaks to Sema::CheckSubtractionOperands() and Sema::CheckCompareOperands(). For example, they both need to operate on the unqualified pointee...
Modified:
cfe/trunk/AST/ASTContext.cpp
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/function.c
Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=46522&r1=46521&r2=46522&view=diff
==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Tue Jan 29 12:58:14 2008
@@ -1617,6 +1617,9 @@
/// C99 6.2.7p1: Two types have compatible types if their types are the
/// same. See 6.7.[2,3,5] for additional rules.
bool ASTContext::typesAreCompatible(QualType lhs, QualType rhs) {
+ if (lhs.getQualifiers() != rhs.getQualifiers())
+ return false;
+
QualType lcanon = lhs.getCanonicalType();
QualType rcanon = rhs.getCanonicalType();
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=46522&r1=46521&r2=46522&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Tue Jan 29 12:58:14 2008
@@ -1337,10 +1337,12 @@
// Either ptr - int or ptr - ptr.
if (const PointerType *LHSPTy = lex->getType()->getAsPointerType()) {
+ QualType lpointee = LHSPTy->getPointeeType();
+
// The LHS must be an object type, not incomplete, function, etc.
- if (!LHSPTy->getPointeeType()->isObjectType()) {
+ if (!lpointee->isObjectType()) {
// Handle the GNU void* extension.
- if (LHSPTy->getPointeeType()->isVoidType()) {
+ if (lpointee->isVoidType()) {
Diag(loc, diag::ext_gnu_void_ptr,
lex->getSourceRange(), rex->getSourceRange());
} else {
@@ -1356,11 +1358,13 @@
// Handle pointer-pointer subtractions.
if (const PointerType *RHSPTy = rex->getType()->getAsPointerType()) {
+ QualType rpointee = RHSPTy->getPointeeType();
+
// RHS must be an object type, unless void (GNU).
- if (!RHSPTy->getPointeeType()->isObjectType()) {
+ if (!rpointee->isObjectType()) {
// Handle the GNU void* extension.
- if (RHSPTy->getPointeeType()->isVoidType()) {
- if (!LHSPTy->getPointeeType()->isVoidType())
+ if (rpointee->isVoidType()) {
+ if (!lpointee->isVoidType())
Diag(loc, diag::ext_gnu_void_ptr,
lex->getSourceRange(), rex->getSourceRange());
} else {
@@ -1371,8 +1375,8 @@
}
// Pointee types must be compatible.
- if (!Context.typesAreCompatible(LHSPTy->getPointeeType(),
- RHSPTy->getPointeeType())) {
+ if (!Context.typesAreCompatible(lpointee.getUnqualifiedType(),
+ rpointee.getUnqualifiedType())) {
Diag(loc, diag::err_typecheck_sub_ptr_compatible,
lex->getType().getAsString(), rex->getType().getAsString(),
lex->getSourceRange(), rex->getSourceRange());
@@ -1446,12 +1450,13 @@
// when handling null pointer constants. One day, we can consider making them
// errors (when -pedantic-errors is enabled).
if (lType->isPointerType() && rType->isPointerType()) { // C99 6.5.8p2
-
+ QualType lpointee = lType->getAsPointerType()->getPointeeType();
+ QualType rpointee = rType->getAsPointerType()->getPointeeType();
+
if (!LHSIsNull && !RHSIsNull && // C99 6.5.9p2
- !lType->getAsPointerType()->getPointeeType()->isVoidType() &&
- !rType->getAsPointerType()->getPointeeType()->isVoidType() &&
- !Context.pointerTypesAreCompatible(lType.getUnqualifiedType(),
- rType.getUnqualifiedType())) {
+ !lpointee->isVoidType() && !lpointee->isVoidType() &&
+ !Context.typesAreCompatible(lpointee.getUnqualifiedType(),
+ rpointee.getUnqualifiedType())) {
Diag(loc, diag::ext_typecheck_comparison_of_distinct_pointers,
lType.getAsString(), rType.getAsString(),
lex->getSourceRange(), rex->getSourceRange());
Modified: cfe/trunk/test/Sema/function.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/function.c?rev=46522&r1=46521&r2=46522&view=diff
==============================================================================
--- cfe/trunk/test/Sema/function.c (original)
+++ cfe/trunk/test/Sema/function.c Tue Jan 29 12:58:14 2008
@@ -1,4 +1,4 @@
-// RUN: clang %s -fsyntax-only
+// RUN: clang %s -fsyntax-only -verify
// PR1892
void f(double a[restrict][5]); // should promote to restrict ptr.
void f(double (* restrict a)[5]);
@@ -6,6 +6,9 @@
int foo (__const char *__path);
int foo(__const char *__restrict __file);
+void func(const char*); //expected-error{{previous declaration is here}}
+void func(char*); //expected-error{{conflicting types for 'func'}}
+
void g(int (*)(const void **, const void **));
void g(int (*compar)()) {
}
More information about the cfe-commits
mailing list