소스 검색

[analyzer] Avoid crash when attempting to evaluate binary operation on LazyCompoundVal.

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
Devin Coughlin 9 년 전
부모
커밋
eb8ffd99ee
2개의 변경된 파일19개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      lib/StaticAnalyzer/Core/SValBuilder.cpp
  2. 14 0
      test/Analysis/string.c

+ 5 - 0
lib/StaticAnalyzer/Core/SValBuilder.cpp

@@ -367,6 +367,11 @@ SVal SValBuilder::evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op,
   if (lhs.isUnknown() || rhs.isUnknown())
   if (lhs.isUnknown() || rhs.isUnknown())
     return UnknownVal();
     return UnknownVal();
 
 
+  if (lhs.getAs<nonloc::LazyCompoundVal>() ||
+      rhs.getAs<nonloc::LazyCompoundVal>()) {
+    return UnknownVal();
+  }
+
   if (Optional<Loc> LV = lhs.getAs<Loc>()) {
   if (Optional<Loc> LV = lhs.getAs<Loc>()) {
     if (Optional<Loc> RV = rhs.getAs<Loc>())
     if (Optional<Loc> RV = rhs.getAs<Loc>())
       return evalBinOpLL(state, op, *LV, *RV, type);
       return evalBinOpLL(state, op, *LV, *RV, type);

+ 14 - 0
test/Analysis/string.c

@@ -756,6 +756,20 @@ void strcmp_unknown_arg (char *unknown) {
 	clang_analyzer_eval(strcmp(unknown, unknown) == 0); // expected-warning{{TRUE}}
 	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()
 // strncmp()
 //===----------------------------------------------------------------------===
 //===----------------------------------------------------------------------===