]> granicus.if.org Git - clang/commitdiff
Specially handle casts to 'void' in AdjustedReturnValueChecker.
authorTed Kremenek <kremenek@apple.com>
Thu, 4 Feb 2010 04:18:55 +0000 (04:18 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 4 Feb 2010 04:18:55 +0000 (04:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95287 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Checker/AdjustedReturnValueChecker.cpp
test/Analysis/misc-ps.m

index 898ce76a99112da2b705bdc1ee81de0ed3343739..483b41b6bdf7bf924e5c13f9e19e0dfedd924d3a 100644 (file)
@@ -43,12 +43,21 @@ void clang::RegisterAdjustedReturnValueChecker(GRExprEngine &Eng) {
 void AdjustedReturnValueChecker::PostVisitCallExpr(CheckerContext &C,
                                                    const CallExpr *CE) {
   
+  // Get the result type of the call.
+  QualType expectedResultTy = CE->getType();
+
   // Fetch the signature of the called function.
   const GRState *state = C.getState();
 
   SVal V = state->getSVal(CE);
   if (V.isUnknown())
     return;
+  
+  // Casting to void?  Discard the value.
+  if (expectedResultTy->isVoidType()) {
+    C.GenerateNode(state->BindExpr(CE, UnknownVal()));
+    return;
+  }                   
 
   const MemRegion *callee = state->getSVal(CE->getCallee()).getAsRegion();
   if (!callee)
@@ -76,8 +85,6 @@ void AdjustedReturnValueChecker::PostVisitCallExpr(CheckerContext &C,
   if (actualResultTy->getAs<ReferenceType>())
     return;
   
-  // Get the result type of the call.
-  QualType expectedResultTy = CE->getType();
 
   // Are they the same?
   if (expectedResultTy != actualResultTy) {
index 949c51019f2525b705745ec2326ee922130e3c9a..8c76ff6de6a816ccc1cb3a08881932d29689b14b 100644 (file)
@@ -893,3 +893,11 @@ int bar_rev95267() {
     return 1;
   return 0;
 }
+
+// Same as previous case, but handle casts to 'void'.
+int bar_rev95274() {
+  void (*Callback_rev95274)(void) = (void (*)(void)) foo_rev95267;
+  (*Callback_rev95274)();
+  return 0;
+}
+