From f8f873deef78de611dd793a1e1201bef0d5a54a3 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Fri, 30 May 2008 18:07:22 +0000 Subject: [PATCH] Make sure to allow assigning a pointer to a bool. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51778 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 25 ++++++++++++++----------- test/Sema/init.c | 8 ++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 7f80203a00..500d5b7786 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1267,10 +1267,10 @@ Sema::AssignConvertType Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { // Get canonical types. We're not formatting these types, just comparing // them. - lhsType = lhsType.getCanonicalType(); - rhsType = rhsType.getCanonicalType(); - - if (lhsType.getUnqualifiedType() == rhsType.getUnqualifiedType()) + lhsType = lhsType.getCanonicalType().getUnqualifiedType(); + rhsType = rhsType.getCanonicalType().getUnqualifiedType(); + + if (lhsType == rhsType) return Compatible; // Common case: fast path an exact match. if (lhsType->isReferenceType() || rhsType->isReferenceType()) { @@ -1278,7 +1278,7 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { return Compatible; return Incompatible; } - + if (lhsType->isObjCQualifiedIdType() || rhsType->isObjCQualifiedIdType()) { if (ObjCQualifiedIdTypesAreCompatible(lhsType, rhsType, false)) return Compatible; @@ -1291,7 +1291,7 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { if (LV->getElementType().getTypePtr() == rhsType.getTypePtr()) return Compatible; } - + // If LHS and RHS are both vectors of integer or both vectors of floating // point types, and the total vector length is the same, allow the // conversion. This is a bitcast; no bits are changed but the result type @@ -1306,14 +1306,14 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { } return Incompatible; } - + if (lhsType->isArithmeticType() && rhsType->isArithmeticType()) return Compatible; - + if (isa(lhsType)) { if (rhsType->isIntegerType()) return IntToPointer; - + if (isa(rhsType)) return CheckPointerTypesForAssignment(lhsType, rhsType); return Incompatible; @@ -1321,14 +1321,17 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { if (isa(rhsType)) { // C99 6.5.16.1p1: the left operand is _Bool and the right is a pointer. - if (lhsType->isIntegerType() && lhsType != Context.BoolTy) + if (lhsType == Context.BoolTy) + return Compatible; + + if (lhsType->isIntegerType()) return PointerToInt; if (isa(lhsType)) return CheckPointerTypesForAssignment(lhsType, rhsType); return Incompatible; } - + if (isa(lhsType) && isa(rhsType)) { if (Context.typesAreCompatible(lhsType, rhsType)) return Compatible; diff --git a/test/Sema/init.c b/test/Sema/init.c index ffe678c5f7..efc934d57a 100644 --- a/test/Sema/init.c +++ b/test/Sema/init.c @@ -42,3 +42,11 @@ short *a2(void) return bp; } + +int pbool(void) { + typedef const _Bool cbool; + _Bool pbool1 = (void *) 0; + cbool pbool2 = &pbool; + return pbool2; +} + -- 2.40.0