[analyzer][NFC][test] Add new RUN lint with support-symbolic-integer-casts=true to svalbuilder-rearrange-comparisons.c

Added a new run line to bolster gradual transition of handling cast operations,
see https://discourse.llvm.org/t/roadmap-of-modeling-symbolic-cast-operations/63107

Differential Revision: https://reviews.llvm.org/D127646
This commit is contained in:
Gabor Marton 2022-06-13 17:04:42 +02:00
parent 794d080e2e
commit 3605ebca32
1 changed files with 34 additions and 4 deletions

View File

@ -1,8 +1,23 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection,core.builtin -analyzer-config aggressive-binary-operation-simplification=true -verify -analyzer-config eagerly-assume=false %s // RUN: %clang_analyze_cc1 \
// RUN: -analyzer-checker=debug.ExprInspection,core.builtin \
// RUN: -analyzer-config aggressive-binary-operation-simplification=true \
// RUN: -analyzer-config support-symbolic-integer-casts=false \
// RUN: -analyzer-config eagerly-assume=false \
// RUN: -verify %s
void clang_analyzer_eval(int x); // RUN: %clang_analyze_cc1 \
void clang_analyzer_denote(int x, const char *literal); // RUN: -analyzer-checker=debug.ExprInspection,core.builtin \
void clang_analyzer_express(int x); // RUN: -analyzer-config aggressive-binary-operation-simplification=true \
// RUN: -analyzer-config support-symbolic-integer-casts=true \
// RUN: -DSUPPORT_SYMBOLIC_INTEGER_CASTS \
// RUN: -analyzer-config eagerly-assume=false \
// RUN: -verify %s
void clang_analyzer_eval(bool x);
template <typename T>
void clang_analyzer_denote(T x, const char *literal);
template <typename T>
void clang_analyzer_express(T x);
void exit(int); void exit(int);
@ -510,6 +525,17 @@ void compare_same_symbol_minus_left_minus_right_int_less(void) {
clang_analyzer_eval(x < y); // expected-warning {{FALSE}} clang_analyzer_eval(x < y); // expected-warning {{FALSE}}
} }
// Rearrange should happen on signed types only (tryRearrange):
//
// // Rearrange signed symbolic expressions only
// if (!SingleTy->isSignedIntegerOrEnumerationType())
// return None;
//
// Without the symbolic casts, the SVal for `x` in `unsigned x = f()` will be
// the signed `int`. However, with the symbolic casts it will be `unsigned`.
// Thus, these tests are meaningful only if the cast is not emitted.
#ifndef SUPPORT_SYMBOLIC_INTEGER_CASTS
void compare_different_symbol_equal_unsigned(void) { void compare_different_symbol_equal_unsigned(void) {
unsigned x = f(), y = f(); unsigned x = f(), y = f();
clang_analyzer_denote(x, "$x"); clang_analyzer_denote(x, "$x");
@ -894,6 +920,10 @@ void compare_different_symbol_minus_left_minus_right_int_less_unsigned(void) {
clang_analyzer_express(x < y); // expected-warning {{$x - $y < 1}} clang_analyzer_express(x < y); // expected-warning {{$x - $y < 1}}
} }
#endif
// These pass even with aggressive-binary-operation-simplification=false
void compare_same_symbol_less_unsigned(void) { void compare_same_symbol_less_unsigned(void) {
unsigned x = f(), y = x; unsigned x = f(), y = x;
clang_analyzer_denote(x, "$x"); clang_analyzer_denote(x, "$x");