From 728a1fb4fd6c1bcb200b5eed398e982fe1856ee1 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 14 Oct 2013 18:55:27 +0000 Subject: [PATCH] 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 --- lib/Sema/SemaChecking.cpp | 3 +++ test/SemaObjC/conversion.m | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test/SemaObjC/conversion.m 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'}} +} + + -- 2.50.1