From: Ted Kremenek Date: Mon, 14 Oct 2013 18:55:27 +0000 (+0000) Subject: GetExprRange() (used by -Wconversion checking) should look through OpaqueValueExprs. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=728a1fb4fd6c1bcb200b5eed398e982fe1856ee1;p=clang GetExprRange() (used by -Wconversion checking) should look through OpaqueValueExprs. Fixes a false positive with -Wconversion involving Objective-C properties. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192611 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 426bf68e1d..94a58cc625 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -4665,6 +4665,9 @@ static IntRange GetExprRange(ASTContext &C, Expr *E, unsigned MaxWidth) { } } + if (OpaqueValueExpr *OVE = dyn_cast(E)) + return GetExprRange(C, OVE->getSourceExpr(), MaxWidth); + if (FieldDecl *BitField = E->getSourceBitField()) return IntRange(BitField->getBitWidthValue(C), BitField->getType()->isUnsignedIntegerOrEnumerationType()); diff --git a/test/SemaObjC/conversion.m b/test/SemaObjC/conversion.m new file mode 100644 index 0000000000..88a1a44b21 --- /dev/null +++ b/test/SemaObjC/conversion.m @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -Wconversion -fsyntax-only %s -verify + +typedef signed char BOOL; +__attribute__((objc_root_class)) @interface RDar14415662 +@property (readonly) BOOL stuff; +@property (readwrite) BOOL otherStuff; +@end + +void radar14415662(RDar14415662 *f, char x, int y) { + f.otherStuff = !f.stuff; // no-warning + BOOL b = !f.stuff; // no-warning + + // True positive to sanity check warning is working. + x = y; // expected-warning {{implicit conversion loses integer precision: 'int' to 'char'}} +} + +