]> granicus.if.org Git - clang/commitdiff
GetExprRange() (used by -Wconversion checking) should look through OpaqueValueExprs.
authorTed Kremenek <kremenek@apple.com>
Mon, 14 Oct 2013 18:55:27 +0000 (18:55 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 14 Oct 2013 18:55:27 +0000 (18:55 +0000)
Fixes a false positive with -Wconversion involving Objective-C properties.

Fixes <rdar://problem/14415662>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192611 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/SemaObjC/conversion.m [new file with mode: 0644]

index 426bf68e1d68c60c8af041636cd98972931b8910..94a58cc625a2df5608539864507aba6cbb61fbae 100644 (file)
@@ -4665,6 +4665,9 @@ static IntRange GetExprRange(ASTContext &C, Expr *E, unsigned MaxWidth) {
     }
   }
 
+  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());
diff --git a/test/SemaObjC/conversion.m b/test/SemaObjC/conversion.m
new file mode 100644 (file)
index 0000000..88a1a44
--- /dev/null
@@ -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'}}
+}
+
+