[PATCH] D139759: [analyzer] Fix assertion in getAPSIntType
Vince Bridgers via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Dec 10 15:12:19 PST 2022
vabridgers updated this revision to Diff 481882.
vabridgers edited the summary of this revision.
vabridgers added a comment.
correct formatting of test case and expand test cases
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139759/new/
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,65 @@
+// RUN: %clang_analyze_cc1 -ffixed-point \
+// RUN: -analyzer-checker=core,debug.ExprInspection -verify %s
+
+// expected-no-diagnostics
+
+// Check that getAPSIntType does not crash
+// when using fixed point types.
+
+enum en_t { en_0 = 1 };
+
+void _enum(int c) {
+ (void)((enum en_t) c >> 4);
+}
+
+void _inttype(int c) {
+ (void)(c >> 4);
+}
+
+void _accum(int c) {
+ (void)((_Accum) c >> 4);
+}
+
+void _fract(int c) {
+ (void)((_Fract) c >> 4);
+}
+
+void _long_fract(int c) {
+ (void)((long _Fract) c >> 4);
+}
+
+void _unsigned_accum(int c) {
+ (void)((unsigned _Accum) c >> 4);
+}
+
+void _short_unsigned_accum(int c) {
+ (void)((short unsigned _Accum) c >> 4);
+}
+
+void _unsigned_fract(int c) {
+ (void)((unsigned _Fract) c >> 4);
+}
+
+void sat_accum(int c) {
+ (void)((_Sat _Accum) c >> 4);
+}
+
+void sat_fract(int c) {
+ (void)((_Sat _Fract) c >> 4);
+}
+
+void sat_long_fract(int c) {
+ (void)((_Sat long _Fract) c >> 4);
+}
+
+void sat_unsigned_accum(int c) {
+ (void)((_Sat unsigned _Accum) c >> 4);
+}
+
+void sat_short_unsigned_accum(int c) {
+ (void)((_Sat short unsigned _Accum) c >> 4);
+}
+
+void sat_unsigned_fract(int c) {
+ (void)((_Sat unsigned _Fract) c >> 4);
+}
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.481882.patch
Type: text/x-patch
Size: 2040 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221210/ac7e30f8/attachment.bin>
More information about the cfe-commits
mailing list