[PATCH] Make -Wuninitialized warn on pointer-to-member and comma operators.

Richard Smith richard at metafoo.co.uk
Thu Dec 12 15:14:33 PST 2013



================
Comment at: lib/Analysis/UninitializedValues.cpp:421-442
@@ -403,10 +420,24 @@
 
+static bool IsPointerToConst(const QualType &QT) {
+  return QT->isAnyPointerType() && QT->getPointeeType().isConstQualified();
+}
+
 void ClassifyRefs::VisitCallExpr(CallExpr *CE) {
-  // If a value is passed by const reference to a function, we should not assume
-  // that it is initialized by the call, and we conservatively do not assume
-  // that it is used.
-  for (CallExpr::arg_iterator I = CE->arg_begin(), E = CE->arg_end();
-       I != E; ++I)
-    if ((*I)->getType().isConstQualified() && (*I)->isGLValue())
-      classify(*I, Ignore);
+  // If a value is passed by const pointer or by const reference to a function,
+  // we should not assume that it is initialized by the call, and we
+  // conservatively do not assume that it is used.
+  for (CallExpr::arg_iterator I = CE->arg_begin(), E = CE->arg_end(); 
+       I != E; ++I) {
+    if ((*I)->isGLValue()) {
+      if ((*I)->getType().isConstQualified())
+        classify((*I), Ignore);
+      continue;
+    } else if (IsPointerToConst((*I)->getType())) {
+      const Expr *Ex = stripCasts(DC->getParentASTContext(), *I);
+      const UnaryOperator *UO = dyn_cast<UnaryOperator>(Ex);
+      if (UO && UO->getOpcode() == UO_AddrOf)
+        Ex = UO->getSubExpr();
+      classify(Ex, Ignore);
+    }
+  }
 }
----------------
It doesn't look like there's a new test case for this change. Is this somehow covered by our existing tests?


http://llvm-reviews.chandlerc.com/D2387



More information about the cfe-commits mailing list