<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Jun 18, 2013, at 16:16 , Anna Zaks <<a href="mailto:ganna@apple.com">ganna@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Author: zaks<br>Date: Tue Jun 18 18:16:15 2013<br>New Revision: 184256<br><br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=184256&view=rev">http://llvm.org/viewvc/llvm-project?rev=184256&view=rev</a><br>Log:<br>[analyzer] Do not report uninitialized value warnings inside swap functions.<br><br>This silences warnings that could occur when one is swapping partially initialized structs. We suppress<br>not only the assignments of uninitialized members, but any values inside swap because swap could<br>potentially be used as a subroutine to swap class members.<br><br>This silences a warning from std::try::function::swap() on partially initialized objects.<br><br>Modified:<br>   cfe/trunk/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp<br>   cfe/trunk/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp<br>   cfe/trunk/test/Analysis/uninit-vals-ps-region.m<br><br>Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp?rev=184256&r1=184255&r2=184256&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp?rev=184256&r1=184255&r2=184256&view=diff</a><br>==============================================================================<br>--- cfe/trunk/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp (original)<br>+++ cfe/trunk/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp Tue Jun 18 18:16:15 2013<br>@@ -40,6 +40,15 @@ void UndefResultChecker::checkPostStmt(c<br>  ProgramStateRef state = C.getState();<br>  const LocationContext *LCtx = C.getLocationContext();<br>  if (state->getSVal(B, LCtx).isUndef()) {<br>+<br>+    // Do not report assignments of uninitialized values inside swap functions.<br>+    // This should allow to swap partially uninitialized structs<br>+    // (<a href="radar://14129997">radar://14129997</a>)<br></div></blockquote><div dir="auto"><br></div><div dir="auto">We generally don't put Radar numbers in the source proper, although they do show up in test files. Also, is there a reason this is in UndefResultChecker and not just UndefinedAssignmentChecker?</div><div dir="auto"><br></div><br><blockquote type="cite"><div style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">+    if (const FunctionDecl *EnclosingFunctionDecl =<br>+        dyn_cast<FunctionDecl>(C.getStackFrame()->getDecl()))<br>+      if (C.getCalleeName(EnclosingFunctionDecl) == "swap")<br>+        return;<br>+<br>    // Generate an error node.<br>    ExplodedNode *N = C.generateSink();<br>    if (!N)<br><br>Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp?rev=184256&r1=184255&r2=184256&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp?rev=184256&r1=184255&r2=184256&view=diff</a><br>==============================================================================<br>--- cfe/trunk/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp (original)<br>+++ cfe/trunk/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp Tue Jun 18 18:16:15 2013<br>@@ -38,6 +38,14 @@ void UndefinedAssignmentChecker::checkBi<br>  if (!val.isUndef())<br>    return;<br><br>+  // Do not report assignments of uninitialized values inside swap functions.<br>+  // This should allow to swap partially uninitialized structs<br>+  // (<a href="radar://14129997">radar://14129997</a>)<br></div></blockquote><div><br></div><div>Ditto about Radar numbers.</div><br><blockquote type="cite"><div style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">+  if (const FunctionDecl *EnclosingFunctionDecl =<br>+      dyn_cast<FunctionDecl>(C.getStackFrame()->getDecl()))<br>+    if (C.getCalleeName(EnclosingFunctionDecl) == "swap")<br>+      return;<br>+<br>  ExplodedNode *N = C.generateSink();<br><br>  if (!N)<br><br>Modified: cfe/trunk/test/Analysis/uninit-vals-ps-region.m<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/uninit-vals-ps-region.m?rev=184256&r1=184255&r2=184256&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/uninit-vals-ps-region.m?rev=184256&r1=184255&r2=184256&view=diff</a><br>==============================================================================<br>--- cfe/trunk/test/Analysis/uninit-vals-ps-region.m (original)<br>+++ cfe/trunk/test/Analysis/uninit-vals-ps-region.m Tue Jun 18 18:16:15 2013<br>@@ -76,3 +76,18 @@ void PR10163 (void) {<br>  test_PR10163(x[1]); // expected-warning{{uninitialized value}}<br>}<br><br>+struct MyStr {<br>+  int x;<br>+  int y;<br>+};<br>+void swap(struct MyStr *To, struct MyStr *From) {<br>+  // This is not really a swap but close enough for our test.<br>+  To->x = From->x;<br>+  To->y = From->y; // no warning<br>+}<br>+int test_undefined_member_assignment_in_swap(struct MyStr *s2) {<br>+  struct MyStr s1;<br>+  s1.x = 5;<br>+  swap(s2, &s1);<br>+  return s2->y; // expected-warning{{Undefined or garbage value returned to caller}}<br>+}<br></div></blockquote></div><br><div>Can we have a path-notes test to prove that the tracing goes all the way back to the initial lack of initialization, and that we get an "assigned here" note inside swap()?</div></body></html>