Modified Type::typesAreCompatible() to use the above.
This fixes the following bug submitted by Keith Bauer (thanks!).
int equal(char *a, const char *b)
{
return a == b;
}
Also tweaked Sema::CheckCompareOperands() to ignore the qualifiers when
comparing two pointer types (though it doesn't relate directly to this bug).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41476
91177308-0d34-0410-b5e6-
96231b3b80d8
return isa<ComplexType>(CanonicalType);
}
+const BuiltinType *Type::getAsBuiltinType() const {
+ // If this is directly a builtin type, return it.
+ if (const BuiltinType *BTy = dyn_cast<BuiltinType>(this))
+ return BTy;
+
+ // If this is a typedef for a builtin type, strip the typedef off without
+ // losing all typedef information.
+ if (isa<BuiltinType>(CanonicalType))
+ return cast<BuiltinType>(cast<TypedefType>(this)->LookThroughTypedefs());
+ return 0;
+}
+
const FunctionType *Type::getAsFunctionType() const {
// If this is directly a function type, return it.
if (const FunctionType *FTy = dyn_cast<FunctionType>(this))
return 0;
}
+bool Type::builtinTypesAreCompatible(QualType lhs, QualType rhs) {
+ const BuiltinType *lBuiltin = lhs->getAsBuiltinType();
+ const BuiltinType *rBuiltin = rhs->getAsBuiltinType();
+
+ return lBuiltin->getKind() == rBuiltin->getKind();
+}
// C99 6.2.7p1: If both are complete types, then the following additional
// requirements apply...FIXME (handle compatibility across source files).
case Type::Tagged: // handle structures, unions
return tagTypesAreCompatible(lcanon, rcanon);
case Type::Builtin:
- return false;
+ return builtinTypesAreCompatible(lcanon, rcanon);
default:
assert(0 && "unexpected type");
}
// All of the following pointer related warnings are GCC extensions, except
// when handling null pointer constants. One day, we can consider making them
// errors (when -pedantic-errors is enabled).
- if (lType->isPointerType() && rType->isPointerType()) {
+ if (lType->isPointerType() && rType->isPointerType()) { // C99 6.5.8p2
if (!LHSIsNull && !RHSIsNull &&
- !Type::pointerTypesAreCompatible(lType, rType)) {
+ !Type::pointerTypesAreCompatible(lType.getUnqualifiedType(),
+ rType.getUnqualifiedType())) {
Diag(loc, diag::ext_typecheck_comparison_of_distinct_pointers,
lType.getAsString(), rType.getAsString(),
lex->getSourceRange(), rex->getSourceRange());
class TagType;
class FunctionType;
class OCUVectorType;
+ class BuiltinType;
/// QualType - For efficiency, we don't store CVR-qualified types as nodes on
/// their own: instead each reference to a type stores the qualifiers. This
// Type Checking Functions: Check to see if this type is structurally the
// specified type, ignoring typedefs, and return a pointer to the best type
// we can.
+ const BuiltinType *getAsBuiltinType() const;
const FunctionType *getAsFunctionType() const;
const PointerType *getAsPointerType() const;
const ReferenceType *getAsReferenceType() const;
static bool referenceTypesAreCompatible(QualType, QualType); // C++ 5.17p6
static bool functionTypesAreCompatible(QualType, QualType); // C99 6.7.5.3p15
static bool arrayTypesAreCompatible(QualType, QualType); // C99 6.7.5.2p6
+ static bool builtinTypesAreCompatible(QualType, QualType);
private:
QualType getCanonicalTypeInternal() const { return CanonicalType; }
friend class QualType;
return C != 0;
}
+int equal(char *a, const char *b)
+{
+ return a == b;
+}
void bar(volatile int *VP, int *P, int A,
_Complex double C, volatile _Complex double VC) {
- VP == P; // expected-warning {{expression result unused}} \
- expected-warning {{comparison}}
+ VP == P; // expected-warning {{expression result unused}}
(void)A;
(void)foo(1,2); // no warning.