[clang] [clang][analyzer] use unqualified canonical type during merging equivalence class (PR #95729)
steakhal wrote: > > Excellent quality. Thank for fixing this. > > Should I fix the other type comparison in static analysis? It looks like not > consider this case at lots of position. > > I think you are right. And in most cases within CSA, we should usually compare canonical types. If you wanna hunt for some, we would be happy to review your findings. https://github.com/llvm/llvm-project/pull/95729 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] use unqualified canonical type during merging equivalence class (PR #95729)
HerrCai0907 wrote: > Excellent quality. Thank for fixing this. Should I fix the other type comparison in static analysis? It looks like not consider this case at lots of position. https://github.com/llvm/llvm-project/pull/95729 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] use unqualified canonical type during merging equivalence class (PR #95729)
https://github.com/HerrCai0907 closed https://github.com/llvm/llvm-project/pull/95729 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] use unqualified canonical type during merging equivalence class (PR #95729)
HerrCai0907 wrote: > Do you need us to merge this, or you have merge rights? Yes. https://github.com/llvm/llvm-project/pull/95729 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] use unqualified canonical type during merging equivalence class (PR #95729)
https://github.com/steakhal approved this pull request. Excellent quality. Thank for fixing this. Do you need us to merge this, or you have merge rights? https://github.com/llvm/llvm-project/pull/95729 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] use unqualified canonical type during merging equivalence class (PR #95729)
https://github.com/NagyDonat approved this pull request. Nice catch, thanks for fixing this bug! https://github.com/llvm/llvm-project/pull/95729 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] use unqualified canonical type during merging equivalence class (PR #95729)
https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/95729 >From 40f18f2be624ed2a5b4922e67e4ed6070d2d2400 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Mon, 17 Jun 2024 00:13:20 + Subject: [PATCH 1/2] [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 , // //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) { >From 572f9daca5b9d36b15122d3dd3454ac21406e7a3 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Mon, 17 Jun 2024 12:30:03 + Subject: [PATCH 2/2] add test --- clang/test/Analysis/equality_tracking.c | 16 1 file changed, 16 insertions(+) diff --git a/clang/test/Analysis/equality_tracking.c b/clang/test/Analysis/equality_tracking.c index e33b95700d002..877486c9133f4 100644 --- a/clang/test/Analysis/equality_tracking.c +++ b/clang/test/Analysis/equality_tracking.c @@ -28,6 +28,22 @@ void zeroImpliesEquality(int a, int b) { clang_analyzer_eval(b != a); // expected-warning{{TRUE}} } +typedef int I32_A; +typedef int I32_B; +void zeroImpliesEqualityWithTypedef(I32_A a, I32_B b) { + clang_analyzer_eval((a - b) == 0); // expected-warning{{UNKNOWN}} + if ((a - b) == 0) { +clang_analyzer_eval(b != a);// expected-warning{{FALSE}} +clang_analyzer_eval(b == a);// expected-warning{{TRUE}} +clang_analyzer_eval(!(a != b)); // expected-warning{{TRUE}} +clang_analyzer_eval(!(b == a)); // expected-warning{{FALSE}} +return; + } + clang_analyzer_eval((a - b) == 0); // expected-warning{{FALSE}} + clang_analyzer_eval(b == a); // expected-warning{{FALSE}} + clang_analyzer_eval(b != a); // expected-warning{{TRUE}} +} + void zeroImpliesReversedEqual(int a, int b) { clang_analyzer_eval((b - a) == 0); // expected-warning{{UNKNOWN}} if ((b - a) == 0) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] use unqualified canonical type during merging equivalence class (PR #95729)
https://github.com/steakhal commented: Awesome. I have one remark though. It would be nice to see tests that does not depend on the errno, as this eqclass merging is a major vore feature, unlike the errno modeling which is an optional feature. If have something in mind, you could add that test in addition you already propose. Again, cool stuff! https://github.com/llvm/llvm-project/pull/95729 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] use unqualified canonical type during merging equivalence class (PR #95729)
llvmbot wrote: @llvm/pr-subscribers-clang-static-analyzer-1 Author: Congcong Cai (HerrCai0907) Changes Fixes: #95658 Unqualified canonical type should be used instead of normal QualType for type equality comparison --- Full diff: https://github.com/llvm/llvm-project/pull/95729.diff 2 Files Affected: - (modified) clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp (+2-1) - (modified) clang/test/Analysis/errno-stdlibraryfunctions.c (+24) ``diff 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 , // //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) { `` https://github.com/llvm/llvm-project/pull/95729 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] use unqualified canonical type during merging equivalence class (PR #95729)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Congcong Cai (HerrCai0907) Changes Fixes: #95658 Unqualified canonical type should be used instead of normal QualType for type equality comparison --- Full diff: https://github.com/llvm/llvm-project/pull/95729.diff 2 Files Affected: - (modified) clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp (+2-1) - (modified) clang/test/Analysis/errno-stdlibraryfunctions.c (+24) ``diff 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 , // //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) { `` https://github.com/llvm/llvm-project/pull/95729 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] use unqualified canonical type during merging equivalence class (PR #95729)
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 Date: Mon, 17 Jun 2024 00:13:20 + 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 , // //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) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits