[clang] [clang][analyzer] use unqualified canonical type during merging equivalence class (PR #95729)
Congcong Cai via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 16 19:39:20 PDT 2024
https://github.com/HerrCai0907 created https://github.com/llvm/llvm-project/pull/95729
Fixes: #95658
Unqualified canonical type should be used instead of normal QualType for type equality comparison
>From 40f18f2be624ed2a5b4922e67e4ed6070d2d2400 Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0907 at 163.com>
Date: Mon, 17 Jun 2024 00:13:20 +0000
Subject: [PATCH] [clang][analyzer] use unqualified canonical type during
merging equivalence class
Fixes: #95658
Unqualified canonical type should be used instead of normal QualType for type equality comparison
---
.../Core/RangeConstraintManager.cpp | 3 ++-
.../test/Analysis/errno-stdlibraryfunctions.c | 24 +++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index c6f87b45ab887..d8c257dbd731e 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2333,7 +2333,8 @@ inline ProgramStateRef EquivalenceClass::merge(RangeSet::Factory &F,
//
// The moment we introduce symbolic casts, this restriction can be
// lifted.
- if (getType() != Other.getType())
+ if (getType()->getCanonicalTypeUnqualified() !=
+ Other.getType()->getCanonicalTypeUnqualified())
return State;
SymbolSet Members = getClassMembers(State);
diff --git a/clang/test/Analysis/errno-stdlibraryfunctions.c b/clang/test/Analysis/errno-stdlibraryfunctions.c
index a28efb764edfd..657aa37a42670 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -75,6 +75,30 @@ void errno_mkdtemp(char *template) {
}
}
+typedef char* CHAR_PTR;
+void errno_mkdtemp2(CHAR_PTR template) {
+ CHAR_PTR Dir = mkdtemp(template);
+ if (Dir == NULL) {
+ clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+ if (errno) {} // no warning
+ } else {
+ clang_analyzer_eval(Dir == template); // expected-warning{{TRUE}}
+ if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
+ }
+}
+
+typedef char const* CONST_CHAR_PTR;
+void errno_mkdtemp3(CHAR_PTR template) {
+ CONST_CHAR_PTR Dir = mkdtemp(template);
+ if (Dir == NULL) {
+ clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+ if (errno) {} // no warning
+ } else {
+ clang_analyzer_eval(Dir == template); // expected-warning{{TRUE}}
+ if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
+ }
+}
+
void errno_getcwd(char *Buf, size_t Sz) {
char *Path = getcwd(Buf, Sz);
if (Sz == 0) {
More information about the cfe-commits
mailing list