[PATCH] D139759: [analyzer] Fix assertion in getAPSIntType

Vince Bridgers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 9 17:27:58 PST 2022


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

getAPSIntType crashes when analzying a simple case that uses a fixed
point type. Just add a check for isFixedPointType() to the assert to
address the problem.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139759

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/test/Analysis/fixed-point.c


Index: clang/test/Analysis/fixed-point.c
===================================================================
--- /dev/null
+++ clang/test/Analysis/fixed-point.c
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -ffixed-point \
+// RUN:   -analyzer-checker=core,debug.ExprInspection -Wno-unused -verify %s
+
+// expected-no-diagnostics
+
+long a(int c) {                                                                       
+  (long _Accum) c >> 4;
+  return c;
+}  
+
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===================================================================
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -152,7 +152,8 @@
       T = AT->getValueType();
     }
 
-    assert(T->isIntegralOrEnumerationType() || Loc::isLocType(T));
+    assert(T->isIntegralOrEnumerationType() || T->isFixedPointType() ||
+           Loc::isLocType(T));
     return APSIntType(Ctx.getIntWidth(T),
                       !T->isSignedIntegerOrEnumerationType());
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139759.481806.patch
Type: text/x-patch
Size: 1115 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221210/5d59801d/attachment-0001.bin>


More information about the cfe-commits mailing list