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

Gabor Marton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 13 08:09:11 PDT 2022


martong created this revision.
martong added reviewers: vabridgers, steakhal.
Herald added subscribers: manas, ASDenysPetrov, gamesh411, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: All.
martong requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127646

Files:
  clang/test/Analysis/svalbuilder-rearrange-comparisons.c
  clang/test/Analysis/svalbuilder-rearrange-comparisons.cpp


Index: clang/test/Analysis/svalbuilder-rearrange-comparisons.cpp
===================================================================
--- clang/test/Analysis/svalbuilder-rearrange-comparisons.cpp
+++ clang/test/Analysis/svalbuilder-rearrange-comparisons.cpp
@@ -1,8 +1,24 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection,core.builtin -analyzer-config aggressive-binary-operation-simplification=true -verify -analyzer-config eagerly-assume=false %s
-
-void clang_analyzer_eval(int x);
-void clang_analyzer_denote(int x, const char *literal);
-void clang_analyzer_express(int x);
+// 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
+
+// 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=true \
+// RUN:    -DSUPPORT_SYMBOLIC_INTEGER_CASTS \
+// RUN:    -analyzer-config eagerly-assume=false \
+// RUN:    -verify %s
+
+template <typename T>
+void clang_analyzer_eval(T 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);
 
@@ -510,6 +526,17 @@
   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) {
   unsigned x = f(), y = f();
   clang_analyzer_denote(x, "$x");
@@ -894,6 +921,10 @@
   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) {
   unsigned x = f(), y = x;
   clang_analyzer_denote(x, "$x");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127646.436397.patch
Type: text/x-patch
Size: 2464 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220613/7b16b537/attachment-0001.bin>


More information about the cfe-commits mailing list