r192611 - GetExprRange() (used by -Wconversion checking) should look through OpaqueValueExprs.

Ted Kremenek kremenek at apple.com
Mon Oct 14 11:55:27 PDT 2013


Author: kremenek
Date: Mon Oct 14 13:55:27 2013
New Revision: 192611

URL: http://llvm.org/viewvc/llvm-project?rev=192611&view=rev
Log:
GetExprRange() (used by -Wconversion checking) should look through OpaqueValueExprs.

Fixes a false positive with -Wconversion involving Objective-C properties.

Fixes <rdar://problem/14415662>.

Added:
    cfe/trunk/test/SemaObjC/conversion.m
Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=192611&r1=192610&r2=192611&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Oct 14 13:55:27 2013
@@ -4665,6 +4665,9 @@ static IntRange GetExprRange(ASTContext
     }
   }
 
+  if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(E))
+    return GetExprRange(C, OVE->getSourceExpr(), MaxWidth);
+
   if (FieldDecl *BitField = E->getSourceBitField())
     return IntRange(BitField->getBitWidthValue(C),
                     BitField->getType()->isUnsignedIntegerOrEnumerationType());

Added: cfe/trunk/test/SemaObjC/conversion.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/conversion.m?rev=192611&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/conversion.m (added)
+++ cfe/trunk/test/SemaObjC/conversion.m Mon Oct 14 13:55:27 2013
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -Wconversion -fsyntax-only %s -verify
+
+typedef signed char BOOL;
+__attribute__((objc_root_class)) @interface RDar14415662
+ at property (readonly) BOOL stuff;
+ at property (readwrite) BOOL otherStuff;
+ at 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'}}
+}
+
+





More information about the cfe-commits mailing list