]> granicus.if.org Git - clang/commitdiff
[analyzer] Avoid crash when attempting to evaluate binary operation on LazyCompoundVal.
authorDevin Coughlin <dcoughlin@apple.com>
Mon, 8 Feb 2016 00:28:24 +0000 (00:28 +0000)
committerDevin Coughlin <dcoughlin@apple.com>
Mon, 8 Feb 2016 00:28:24 +0000 (00:28 +0000)
Instead, return UnknownValue if either operand is a nonloc::LazyCompoundVal. This is a
spot fix for PR 24951.

rdar://problem/23682244

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

lib/StaticAnalyzer/Core/SValBuilder.cpp
test/Analysis/string.c

index 22bc14edd687e9d28d828f2410bba27b8c90ab17..72bcdd9ecb06b602d0fd3dfae24977134bb42ab5 100644 (file)
@@ -367,6 +367,11 @@ SVal SValBuilder::evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op,
   if (lhs.isUnknown() || rhs.isUnknown())
     return UnknownVal();
 
+  if (lhs.getAs<nonloc::LazyCompoundVal>() ||
+      rhs.getAs<nonloc::LazyCompoundVal>()) {
+    return UnknownVal();
+  }
+
   if (Optional<Loc> LV = lhs.getAs<Loc>()) {
     if (Optional<Loc> RV = rhs.getAs<Loc>())
       return evalBinOpLL(state, op, *LV, *RV, type);
index 9fd3efb5c2d773a16c00e9a3c0e84ab15d15f0a7..c65d2be1a40285234735c382e2a0db5691f8677c 100644 (file)
@@ -756,6 +756,20 @@ void strcmp_unknown_arg (char *unknown) {
        clang_analyzer_eval(strcmp(unknown, unknown) == 0); // expected-warning{{TRUE}}
 }
 
+union argument {
+   char *f;
+};
+
+void function_pointer_cast_helper(char **a) {
+  strcmp("Hi", *a); // PR24951 crash
+}
+
+void strcmp_union_function_pointer_cast(union argument a) {
+  void (*fPtr)(union argument *) = (void (*)(union argument *))function_pointer_cast_helper;
+
+  fPtr(&a);
+}
+
 //===----------------------------------------------------------------------===
 // strncmp()
 //===----------------------------------------------------------------------===