[PATCH] D105340: [analyzer] Produce SymbolCast symbols for integral types in SValBuilder::evalCast

Valeriy Savchenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 2 03:29:59 PDT 2021


vsavchenko added a comment.

Hey, thanks for starting on splitting into more pieces!



================
Comment at: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h:96
                        QualType OriginalTy);
+  SVal simplifySymbolCast(nonloc::SymbolVal V, QualType CastTy);
 
----------------
What does it do and what should I give it?


================
Comment at: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:510-546
-// Handles casts of type CK_IntegralCast.
-// At the moment, this function will redirect to evalCast, except when the range
-// of the original value is known to be greater than the max of the target type.
-SVal SValBuilder::evalIntegralCast(ProgramStateRef state, SVal val,
-                                   QualType castTy, QualType originalTy) {
-  // No truncations if target type is big enough.
-  if (getContext().getTypeSize(castTy) >= getContext().getTypeSize(originalTy))
----------------
I'd like to see the motivation about why this code is removed.
My main concern is this:
  * If removing `evalIntegralCast` is essential for this feature and is not an NFC: it should also obey the new analyzer option.
  * If it is NFC, and we can safely remove this function no matter what the value of the option is, it should be a separate patch.


================
Comment at: clang/test/Analysis/bool-assignment.c:46-50
 #ifdef ANALYZER_CM_Z3
     BOOL x = y; // expected-warning {{Assignment of a non-Boolean value}}
 #else
-    BOOL x = y; // no-warning
+    BOOL x = y; // expected-warning {{Assignment of a non-Boolean value}}
 #endif
----------------
If Z3 and not Z3 are the same now, we can simply merge two cases and remove preprocessor directive.


================
Comment at: clang/test/Analysis/produce-symbolcast.cpp:1
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection -analyzer-config handle-integral-cast-for-ranges=true -verify %s
+
----------------
This test is failing on my desktop, when I downloaded your patch:
```
error: 'warning' diagnostics expected but not seen: 
  File .../produce-symbolcast.cpp Line 67: (long) (reg_$0<char x>)
  File .../produce-symbolcast.cpp Line 79: (long long) ((unsigned long) (reg_$0<char x>))
  File .../produce-symbolcast.cpp Line 122: (unsigned long) (reg_$0<char x>)
  File .../produce-symbolcast.cpp Line 134: (unsigned long long) ((unsigned long) (reg_$0<char x>))
  File .../produce-symbolcast.cpp Line 192: (long) (reg_$0<short x>)
  File .../produce-symbolcast.cpp Line 204: (long long) ((unsigned long) (reg_$0<short x>))
  File .../produce-symbolcast.cpp Line 247: (unsigned long) (reg_$0<short x>)
  File .../produce-symbolcast.cpp Line 259: (unsigned long long) ((unsigned long) (reg_$0<short x>))
  File .../produce-symbolcast.cpp Line 317: (long) (reg_$0<int x>)
  File .../produce-symbolcast.cpp Line 329: (long long) ((unsigned long) (reg_$0<int x>))
  File .../produce-symbolcast.cpp Line 372: (unsigned long) (reg_$0<int x>)
  File .../produce-symbolcast.cpp Line 384: (unsigned long long) ((unsigned long) (reg_$0<int x>))
  File .../produce-symbolcast.cpp Line 448: (long long) (reg_$0<long x>)
  File .../produce-symbolcast.cpp Line 454: (long long) ((unsigned long) (reg_$0<long x>))
  File .../produce-symbolcast.cpp Line 492: (unsigned long) (reg_$0<long x>)
  File .../produce-symbolcast.cpp Line 497: (unsigned long) (reg_$0<long x>)
  File .../produce-symbolcast.cpp Line 503: (unsigned long long) (reg_$0<long x>)
  File .../produce-symbolcast.cpp Line 509: (unsigned long long) ((unsigned long) (reg_$0<long x>))
  File .../produce-symbolcast.cpp Line 562: (long) (reg_$0<llong x>)
  File .../produce-symbolcast.cpp Line 567: (long) (reg_$0<llong x>)
  File .../produce-symbolcast.cpp Line 574: (long) (reg_$0<llong x>)
  File .../produce-symbolcast.cpp Line 579: (unsigned long) (reg_$0<llong x>)
  File .../produce-symbolcast.cpp Line 617: (unsigned long) (reg_$0<llong x>)
  File .../produce-symbolcast.cpp Line 622: (unsigned long) (reg_$0<llong x>)
  File .../produce-symbolcast.cpp Line 629: (unsigned long long) ((long) (reg_$0<llong x>))
  File .../produce-symbolcast.cpp Line 634: (unsigned long long) ((unsigned long) (reg_$0<llong x>))
  File .../produce-symbolcast.cpp Line 937: (long) (reg_$0<uint x>)
  File .../produce-symbolcast.cpp Line 949: (long long) ((long) (reg_$0<uint x>))
  File .../produce-symbolcast.cpp Line 992: (unsigned long) (reg_$0<uint x>)
  File .../produce-symbolcast.cpp Line 1004: (unsigned long long) ((long) (reg_$0<uint x>))
  File .../produce-symbolcast.cpp Line 1062: (long) (reg_$0<ulong x>)
  File .../produce-symbolcast.cpp Line 1067: (long) (reg_$0<ulong x>)
  File .../produce-symbolcast.cpp Line 1074: (long long) ((long) (reg_$0<ulong x>))
  File .../produce-symbolcast.cpp Line 1078: (long long) (reg_$0<ulong x>)
  File .../produce-symbolcast.cpp Line 1129: (unsigned long long) ((long) (reg_$0<ulong x>))
  File .../produce-symbolcast.cpp Line 1133: (unsigned long long) (reg_$0<ulong x>)
  File .../produce-symbolcast.cpp Line 1187: (long) (reg_$0<ullong x>)
  File .../produce-symbolcast.cpp Line 1192: (long) (reg_$0<ullong x>)
  File .../produce-symbolcast.cpp Line 1199: (long long) ((long) (reg_$0<ullong x>))
  File .../produce-symbolcast.cpp Line 1204: (long long) ((unsigned long) (reg_$0<ullong x>))
  File .../produce-symbolcast.cpp Line 1242: (unsigned long) (reg_$0<ullong x>)
  File .../produce-symbolcast.cpp Line 1247: (unsigned long) (reg_$0<ullong x>)
  File .../produce-symbolcast.cpp Line 1254: (unsigned long long) ((long) (reg_$0<ullong x>))
  File .../produce-symbolcast.cpp Line 1259: (unsigned long long) ((unsigned long) (reg_$0<ullong x>))
error: 'warning' diagnostics seen but not expected: 
  File .../produce-symbolcast.cpp Line 67: (long) ((unsigned int) (reg_$0<char x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 79: (long long) (reg_$0<char x>) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 122: (unsigned long) ((unsigned int) (reg_$0<char x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 134: (unsigned long long) (reg_$0<char x>) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 192: (long) ((unsigned int) (reg_$0<short x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 204: (long long) (reg_$0<short x>) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 247: (unsigned long) ((unsigned int) (reg_$0<short x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 259: (unsigned long long) (reg_$0<short x>) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 317: (long) ((unsigned int) (reg_$0<int x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 329: (long long) (reg_$0<int x>) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 372: (unsigned long) ((unsigned int) (reg_$0<int x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 384: (unsigned long long) (reg_$0<int x>) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 448: (long long) ((int) (reg_$0<long x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 454: (long long) (reg_$0<long x>) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 492: (unsigned long) ((int) (reg_$0<long x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 497: (unsigned long) ((unsigned int) (reg_$0<long x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 503: (unsigned long long) ((int) (reg_$0<long x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 509: (unsigned long long) (reg_$0<long x>) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 562: (long) ((int) (reg_$0<llong x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 567: (long) ((unsigned int) (reg_$0<llong x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 574: reg_$0<llong x> [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 579: reg_$0<llong x> [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 617: (unsigned long) ((int) (reg_$0<llong x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 622: (unsigned long) ((unsigned int) (reg_$0<llong x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 629: (unsigned long long) (reg_$0<llong x>) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 634: (unsigned long long) (reg_$0<llong x>) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 937: (long) ((int) (reg_$0<uint x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 949: (long long) (reg_$0<uint x>) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 992: (unsigned long) ((int) (reg_$0<uint x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 1004: (unsigned long long) (reg_$0<uint x>) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 1062: (long) ((int) (reg_$0<ulong x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 1067: (long) ((unsigned int) (reg_$0<ulong x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 1074: (long long) (reg_$0<ulong x>) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 1078: (long long) ((unsigned int) (reg_$0<ulong x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 1129: (unsigned long long) (reg_$0<ulong x>) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 1133: (unsigned long long) ((unsigned int) (reg_$0<ulong x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 1187: (long) ((int) (reg_$0<ullong x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 1192: (long) ((unsigned int) (reg_$0<ullong x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 1199: (long long) (reg_$0<ullong x>) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 1204: (long long) (reg_$0<ullong x>) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 1242: (unsigned long) ((int) (reg_$0<ullong x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 1247: (unsigned long) ((unsigned int) (reg_$0<ullong x>)) [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 1254: reg_$0<ullong x> [debug.ExprInspection]
  File .../produce-symbolcast.cpp Line 1259: reg_$0<ullong x> [debug.ExprInspection]
88 errors generated.
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105340/new/

https://reviews.llvm.org/D105340



More information about the cfe-commits mailing list