[clang] [Clang][NFC] Use `llvm::sort()` (PR #140337)

2025-05-19 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: hi, what is the motivation of changing `std::sort` to `llvm:sort`? https://github.com/llvm/llvm-project/pull/140337 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][ExprConst] allow single element access of vector object to be constant expression (PR #101126)

2025-05-19 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: > Can you file an issue so we don't lose track of the bug? Looks like we have an issue already #140348 @AaronBallman do you think my original example is well-defined according to the standard? I saw there is a warning `constexpr constructor that does not initialize all memb

[clang] [clang][ExprConst] allow single element access of vector object to be constant expression (PR #101126)

2025-05-16 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: ``` typedef __attribute__((__ext_vector_type__(2))) float float2; struct vec2 { float2 _v; public: constexpr vec2(float x, float y) { _v.x = x; _v.y = y; } }; constexpr struct vec2 f() { return vec2(1.0, 1.0); } int main() { vec2 S = f(); } `

[clang] [-Wunsafe-buffer-usage] Fix false warnings when const sized array is safely accessed (array [idx %const]) (PR #140113)

2025-05-16 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 approved this pull request. LGTM! (AI comments in this PR aren't very helpful IMO 😅) https://github.com/llvm/llvm-project/pull/140113 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bi

[clang] [analyzer] Fix crashing __builtin_bit_cast (PR #139188)

2025-05-13 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 closed https://github.com/llvm/llvm-project/pull/139188 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Fix crashing __builtin_bit_cast (PR #139188)

2025-05-12 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/139188 Rate limit · GitHub body { background-color: #f6f8fa; color: #24292e; font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,s

[clang] [StaticAnalyzer] Handle `__builtin_bit_cast` (PR #139188)

2025-05-10 Thread Ziqing Luo via cfe-commits
@@ -1,5 +1,5 @@ // RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown -verify %s \ -// RUN: -analyzer-checker=core,debug.ExprInspection +// RUN: -analyzer-checker=debug.ExprInspection -analyzer-disable-checker=core ziqingluo-90 wrote: Oh, I was going to

[clang] [StaticAnalyzer] Handle `__builtin_bit_cast` (PR #139188)

2025-05-09 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: This fix should solve https://github.com/llvm/llvm-project/issues/71174, and https://github.com/llvm/llvm-project/issues/137417 https://github.com/llvm/llvm-project/pull/139188 ___ cfe-commits mailing list cfe-commits@lists.llvm.or

[clang] [StaticAnalyzer] Handle `__builtin_bit_cast` (PR #139188)

2025-05-09 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: Thanks for reviewing! https://github.com/llvm/llvm-project/pull/139188 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [StaticAnalyzer] Handle `__builtin_bit_cast` (PR #139188)

2025-05-09 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/139188 Rate limit · GitHub body { background-color: #f6f8fa; color: #24292e; font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,s

[clang] [StaticAnalyzer] Handle `__builtin_bit_cast` (PR #139188)

2025-05-09 Thread Ziqing Luo via cfe-commits
@@ -285,15 +285,43 @@ void ExprEngine::VisitCast(const CastExpr *CastE, const Expr *Ex, ExplodedNodeSet dstPreStmt; getCheckerManager().runCheckersForPreStmt(dstPreStmt, Pred, CastE, *this); - if (CastE->getCastKind() == CK_LValueToRValue || - CastE->getCastKind() =

[clang] [StaticAnalyzer] Handle `__builtin_bit_cast` (PR #139188)

2025-05-08 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/139188 >From 95ac7cf69dbd683f70b123446115fe3893844526 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 8 May 2025 17:48:41 -0700 Subject: [PATCH 1/2] [StaticAnalyzer] Handle __builtin_bit_cast Previously, CSA

[clang] [StaticAnalyzer] Handle `__builtin_bit_cast` (PR #139188)

2025-05-08 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/139188 I am investigating a CSA crash: https://godbolt.org/z/fEExYqoWM. If one changes the `__builtin_bit_cast` to a C-style cast, the test will be fine. So the problem is specific to `__builtin_bit_cast`. Loo

[clang] [analyzer] Make it a noop when initializing a field of empty record (PR #138594)

2025-05-07 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: Re-landed: https://github.com/llvm/llvm-project/commit/b756c82bfacb2822cd516c32ae3c406e71448c0a https://github.com/llvm/llvm-project/pull/138594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin

[clang] [analyzer] Make it a noop when initializing a field of empty record (PR #138594)

2025-05-07 Thread Ziqing Luo via cfe-commits
@@ -715,7 +716,11 @@ void ExprEngine::handleConstructor(const Expr *E, // actually make things worse. Placement new makes this tricky as well, // since it's then possible to be initializing one part of a multi- // dimensional array. -State = Stat

[clang] b756c82 - Re-land "[analyzer] Make it a noop when initializing a field of empty record" (#138951)

2025-05-07 Thread Ziqing Luo via cfe-commits
Author: Ziqing Luo Date: 2025-05-07T15:55:52-07:00 New Revision: b756c82bfacb2822cd516c32ae3c406e71448c0a URL: https://github.com/llvm/llvm-project/commit/b756c82bfacb2822cd516c32ae3c406e71448c0a DIFF: https://github.com/llvm/llvm-project/commit/b756c82bfacb2822cd516c32ae3c406e71448c0a.diff LO

[clang] [StaticAnalyzer] Make it a noop when initializing a field of empty record (PR #138594)

2025-05-07 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/138594 Rate limit · GitHub body { background-color: #f6f8fa; color: #24292e; font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,s

[clang] [StaticAnalyzer] Make it a noop when initializing a field of empty record (PR #138594)

2025-05-07 Thread Ziqing Luo via cfe-commits
@@ -715,7 +716,11 @@ void ExprEngine::handleConstructor(const Expr *E, // actually make things worse. Placement new makes this tricky as well, // since it's then possible to be initializing one part of a multi- // dimensional array. -State = Stat

[clang] [StaticAnalyzer] Make it a noop when initializing a field of empty record (PR #138594)

2025-05-06 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/138594 >From 4e6f2ce82744322a35614532732281eacb2fe79a Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Mon, 5 May 2025 14:27:48 -0700 Subject: [PATCH 1/2] [StaticAnalyzer] Make it a noop when initializing a field

[clang] [StaticAnalyzer] Make it a noop when initializing a field of empty record (PR #138594)

2025-05-06 Thread Ziqing Luo via cfe-commits
@@ -715,7 +717,11 @@ void ExprEngine::handleConstructor(const Expr *E, // actually make things worse. Placement new makes this tricky as well, // since it's then possible to be initializing one part of a multi- // dimensional array. -State = Stat

[clang] [libcxx] Reland: [clang] unified CWG2398 and P0522 changes; finishes implementation of P3310 (PR #124137)

2025-05-05 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: > @ziqingluo-90 I had already responded here: [#130778 > (comment)](https://github.com/llvm/llvm-project/issues/130778#issuecomment-2843256610) > > I think you moved your post between issues after I had responded. @mizvekov Oh, I see! Thank you! https://github.com/llvm/ll

[clang] [libcxx] Reland: [clang] unified CWG2398 and P0522 changes; finishes implementation of P3310 (PR #124137)

2025-05-05 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: > Hi @mizvekov > > I believe this change is impacting our downstream compiler. Here is a minimal > example: > > ``` > #include > #include > namespace { > > template > class ForEach; // intentionally undefined >

[clang] [StaticAnalyzer] Make it a noop when initializing a field of empty record (PR #138594)

2025-05-05 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: CC: @dtarditi https://github.com/llvm/llvm-project/pull/138594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [StaticAnalyzer] Make it a noop when initializing a field of empty record (PR #138594)

2025-05-05 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/138594 Previously, Static Analyzer initializes empty type fields with zeroes. This can cause problems when those fields have no unique addresses. For example, https://github.com/llvm/llvm-project/issues/137252.

[clang] [libcxx] Reland: [clang] unified CWG2398 and P0522 changes; finishes implementation of P3310 (PR #124137)

2025-04-30 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: Hi @mizvekov I believe this change is impacting our downstream compiler. Here is a minimal example: ``` #include #include namespace { template class ForEach; // intentionally undefined

[clang] [-Wunsafe-buffer-usage] Fix a bug that wrongly assumed CXXMethodDecl always has an identifier (PR #137248)

2025-04-24 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 closed https://github.com/llvm/llvm-project/pull/137248 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [-Wunsafe-buffer-usage] Fix a bug that wrongly assumed CXXMethodDecl always has an identifier (PR #137248)

2025-04-24 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/137248 >From f9e68fd71677e047ee82992f2034bd62958ecbed Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 24 Apr 2025 13:29:24 -0700 Subject: [PATCH 1/3] [-Wunsafe-buffer-usage] Fix a bug that wrongly assumed CX

[clang] [-Wunsafe-buffer-usage] Fix a bug that wrongly assumed CXXMethodDecl always has an identifier (PR #137248)

2025-04-24 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: CC: @dtarditi https://github.com/llvm/llvm-project/pull/137248 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [NFC][Static Analyzer] Rename and discuss about `NotNullConstraint` & `NotNullBufferConstraint` (PR #131374)

2025-04-05 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/131374 >From fdc265eeca36dc877f56389d8dba39b517e6 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Fri, 14 Mar 2025 11:13:46 -0700 Subject: [PATCH 1/2] [NFC][Static Analyzer] Rename `NotNullConstraint` & `NotN

[clang] [NFC][Static Analyzer] Rename and discuss about `NotNullConstraint` & `NotNullBufferConstraint` (PR #131374)

2025-04-05 Thread Ziqing Luo via cfe-commits
@@ -1165,7 +1165,7 @@ ProgramStateRef StdLibraryFunctionsChecker::NotNullConstraint::apply( return State->assume(L, CannotBeNull); } -void StdLibraryFunctionsChecker::NotNullConstraint::describe( +void StdLibraryFunctionsChecker::NullnessConstraint::describe( Descripti

[clang] [NFC][Static Analyzer] Rename and discuss about `NotNullConstraint` & `NotNullBufferConstraint` (PR #131374)

2025-03-24 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/131374 >From fdc265eeca36dc877f56389d8dba39b517e6 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Fri, 14 Mar 2025 11:13:46 -0700 Subject: [PATCH 1/3] [NFC][Static Analyzer] Rename `NotNullConstraint` & `NotN

[clang] [NFC] [ASTMatchers] Share code of `forEachArgumentWithParamType` with UnsafeBufferUsage (PR #132387)

2025-03-21 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: Hi @ilya-biryukov, thank you for continuing to improve this! I'm currently dealing with downstream conflicts with your previous patch. Please do not merge this PR this week, otherwise it may slow down our CI. Thanks! https://github.com/llvm/llvm-project/pull/132387 _

[clang] [NFC][Static Analyzer] Rename and discuss about `NotNullConstraint` & `NotNullBufferConstraint` (PR #131374)

2025-03-20 Thread Ziqing Luo via cfe-commits
@@ -436,9 +436,9 @@ class StdLibraryFunctionsChecker llvm::raw_ostream &Out) const override; ValueConstraintPtr negate() const override { - NotNullBufferConstraint Tmp(*this); + BufferNullnessConstraint Tmp(*this); Tmp.Cannot

[clang] [NFC][Static Analyzer] Rename and discuss about `NotNullConstraint` & `NotNullBufferConstraint` (PR #131374)

2025-03-14 Thread Ziqing Luo via cfe-commits
@@ -436,9 +436,9 @@ class StdLibraryFunctionsChecker llvm::raw_ostream &Out) const override; ValueConstraintPtr negate() const override { - NotNullBufferConstraint Tmp(*this); + BufferNullnessConstraint Tmp(*this); Tmp.Cannot

[clang] [NFC][Static Analyzer] Rename and discuss about `NotNullConstraint` & `NotNullBufferConstraint` (PR #131374)

2025-03-14 Thread Ziqing Luo via cfe-commits
@@ -1165,7 +1165,7 @@ ProgramStateRef StdLibraryFunctionsChecker::NotNullConstraint::apply( return State->assume(L, CannotBeNull); } -void StdLibraryFunctionsChecker::NotNullConstraint::describe( +void StdLibraryFunctionsChecker::NullnessConstraint::describe( Descripti

[clang] [NFC][Static Analyzer] Rename and discuss about `NotNullConstraint` & `NotNullBufferConstraint` (PR #131374)

2025-03-14 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/131374 NotNullConstraint is used to check both null and non-null of a pointer. So the name, which was created originally for just checking non-nullness, becomes less suitable. The same reason applies to `NotNull

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #125492)

2025-03-12 Thread Ziqing Luo via cfe-commits
@@ -186,106 +212,193 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor { return DynamicRecursiveASTVisitor::TraverseStmt(Node); } + void setASTContext(ASTContext &Context) { ActiveASTContext = &Context; } + + void setHandler(const UnsafeBufferUsageHa

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #125492)

2025-03-12 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 approved this pull request. https://github.com/llvm/llvm-project/pull/125492 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #125492)

2025-03-12 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: Please wait a day or two for @jkorous-apple , @malavikasamak and @dtarditi to take another look. https://github.com/llvm/llvm-project/pull/125492 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bi

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #125492)

2025-03-12 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: I don't have big concerns here. Thank you again @ivanaivanovska and @ilya-biryukov for this effort! It is also going to be easier to debug and will open more opportunities for optimization this way. (E.g., I'd like to optimize how "printf" functions are matched, but was ho

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #125492)

2025-03-12 Thread Ziqing Luo via cfe-commits
@@ -1670,30 +1936,41 @@ class ULCArraySubscriptGadget : public FixableGadget { }; // Fixable gadget to handle stand alone pointers of the form `UPC(DRE)` in the -// unspecified pointer context (isInUnspecifiedPointerContext). The gadget emits -// fixit of the form `UPC(DRE.da

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #125492)

2025-03-12 Thread Ziqing Luo via cfe-commits
@@ -68,32 +70,57 @@ static std::string getDREAncestorString(const DeclRefExpr *DRE, if (StParents.size() > 1) return "unavailable due to multiple parents"; -if (StParents.size() == 0) +if (StParents.empty()) break; St = StParents.begin()->get();

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #125492)

2025-03-11 Thread Ziqing Luo via cfe-commits
@@ -1139,26 +1276,30 @@ class ArraySubscriptGadget : public WarningGadget { const ArraySubscriptExpr *ASE; public: - ArraySubscriptGadget(const MatchFinder::MatchResult &Result) + ArraySubscriptGadget(const MatchResult &Result) : WarningGadget(Kind::ArraySubscript),

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #125492)

2025-03-11 Thread Ziqing Luo via cfe-commits
@@ -1139,26 +1276,30 @@ class ArraySubscriptGadget : public WarningGadget { const ArraySubscriptExpr *ASE; public: - ArraySubscriptGadget(const MatchFinder::MatchResult &Result) + ArraySubscriptGadget(const MatchResult &Result) : WarningGadget(Kind::ArraySubscript),

[clang] [StaticAnalyzer] Relax the pre-condition of 'setsockopt' (PR #130683)

2025-03-11 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: Thanks for reviewing! I will create another PR for my questions. https://github.com/llvm/llvm-project/pull/130683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [StaticAnalyzer] Relax the pre-condition of 'setsockopt' (PR #130683)

2025-03-11 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 closed https://github.com/llvm/llvm-project/pull/130683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [-Wunsafe-buffer-usage] Add alloc_size knowledge to the 2-param span constructor warning (PR #114894)

2025-03-07 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 closed https://github.com/llvm/llvm-project/pull/114894 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [-Wunsafe-buffer-usage] Fix a potential overflow bug reported by #126334 (PR #129169)

2025-02-28 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 closed https://github.com/llvm/llvm-project/pull/129169 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [-Wunsafe-buffer-usage] Fix a potential overflow bug reported by #126334 (PR #129169)

2025-02-27 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/129169 `MeasureTokenLength` may return an unsigned 0 representing failure in obtaining length of a token. The analysis now gives up on such cases. Otherwise, there might be issues caused by unsigned integer "ove

[clang] [-Wunsafe-buffer-usage] Fix a potential overflow bug reported by #126334 (PR #129169)

2025-02-27 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: CC: @dtarditi https://github.com/llvm/llvm-project/pull/129169 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [NFC] Add release notes for -Wunsafe-buffer-usage-in-libc-call (PR #126975)

2025-02-20 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 closed https://github.com/llvm/llvm-project/pull/126975 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [-Wunsafe-buffer-usage] add test for constexpr size in snprintf (#119786) (PR #126826)

2025-02-13 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: Thank you @tsepez https://github.com/llvm/llvm-project/pull/126826 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [NFC] Add release notes for -Wunsafe-buffer-usage-in-libc-call (PR #126975)

2025-02-12 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/126975 `-Wunsafe-buffer-usage-in-libc-call` is a subgroup of `-Wunsafe-buffer-usage` that warns about unsafe libc function calls. >From 49cfb174e21290918d30928397e6d0d44a521b66 Mon Sep 17 00:00:00 2001 From: Ziqi

[clang] [-Wunsafe-buffer-usage] add test for constexpr size in snprintf (#119786) (PR #126826)

2025-02-12 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 approved this pull request. LGTM, but I think we can keep the test of `sizeof(b)` and add yours at a new line. Thanks. https://github.com/llvm/llvm-project/pull/126826 ___ cfe-commits mailing list cfe-commits@lists.ll

[clang] [-Wunsafe-buffer-usage] Fix assert when constexpr size passed to snprintf() (#119786) (PR #124022)

2025-02-11 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: > When possible we should always add tests, I think the right place would be: > > https://github.com/llvm/llvm-project/blob/main/clang/test/SemaCXX/warn-unsafe-buffer-usage-libc-functions.cpp > > CC @ziqingluo-90 > > Do we need a release note or is this feature clang-20? T

[clang] [-Wunsafe-buffer-usage] Fix assert when constexpr size passed to snprintf() (#119786) (PR #124022)

2025-02-06 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 approved this pull request. Thank you for the fix! I am curious if you have a counterexample? Because I thought that `Size` must have an integral type. https://github.com/llvm/llvm-project/pull/124022 ___ cfe-commits m

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #125492)

2025-02-05 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: > > I added @ziqingluo-90 @jkorous-apple as reviewers since you've approved > > recent changes to this warning. Please let us know if you're the right > > reviewers for this and feel free to loop in more people if necessary. > > Thank you @ivanaivanovska, the profiling and

[clang] [Wunsafe-buffer-usage] False positives for & expression indexing constant size array (arr[anything & 0]) (PR #112284)

2025-02-05 Thread Ziqing Luo via cfe-commits
@@ -431,6 +431,122 @@ AST_MATCHER(CXXConstructExpr, isSafeSpanTwoParamConstruct) { return false; } +class MaxValueEval : public ConstStmtVisitor { + + ASTContext &Context; + llvm::APInt Max; + unsigned bit_width; + +public: + typedef ConstStmtVisitor VisitorBase; + + e

[clang] [Wunsafe-buffer-usage] False positives for & expression indexing constant size array (arr[anything & 0]) (PR #112284)

2025-02-05 Thread Ziqing Luo via cfe-commits
@@ -431,6 +431,122 @@ AST_MATCHER(CXXConstructExpr, isSafeSpanTwoParamConstruct) { return false; } +class MaxValueEval : public ConstStmtVisitor { + + ASTContext &Context; + llvm::APInt Max; + unsigned bit_width; + +public: + typedef ConstStmtVisitor VisitorBase; + + e

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-30 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 closed https://github.com/llvm/llvm-project/pull/124477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-30 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/124477 >From 1f67a396d917428ff35ca54ecb2d9124c14342de Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 30 Jan 2025 12:24:45 -0800 Subject: [PATCH 1/2] [StaticAnalyzer] Add reproducers for a bug in VisitObjCFo

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-30 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: @steakhal I have added your test on behalf of you here: https://github.com/llvm/llvm-project/pull/124477/commits/b932fb61338ed6ec47db351240dc65b9454ba28c https://github.com/llvm/llvm-project/pull/124477 ___ cfe-commits mailing list

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-30 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/124477 >From b932fb61338ed6ec47db351240dc65b9454ba28c Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 30 Jan 2025 12:24:45 -0800 Subject: [PATCH 1/2] [StaticAnalyzer] Add reproducers for a bug in VisitObjCFo

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-30 Thread Ziqing Luo via cfe-commits
@@ -124,24 +124,26 @@ void ExprEngine::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S, bool isContainerNull = state->isNull(collectionV).isConstrainedTrue(); - ExplodedNodeSet dstLocation; - evalLocation(dstLocation, S, elem, Pred, state, elementV, false); +

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-30 Thread Ziqing Luo via cfe-commits
@@ -124,24 +124,26 @@ void ExprEngine::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S, bool isContainerNull = state->isNull(collectionV).isConstrainedTrue(); - ExplodedNodeSet dstLocation; - evalLocation(dstLocation, S, elem, Pred, state, elementV, false); ---

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-30 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: > I wanted to push to your branch but for some reason I could not. Here is what > I would have proposed to unblock this change: > > ```diff > commit ab9670b613be2bdd802342f031bd5e3d20680925 > Author: Balazs Benics > Date: 2025.01.29 13:02:16 > > Add a unittest demons

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-30 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/124477 >From 635cba186fb9cda4718263caa0d349729279390d Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 30 Jan 2025 12:24:45 -0800 Subject: [PATCH 1/2] [StaticAnalyzer] Add a reproducer for a bug in VisitObjCF

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-27 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: CC: @dtarditi https://github.com/llvm/llvm-project/pull/124477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-26 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 unassigned https://github.com/llvm/llvm-project/pull/124477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-26 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 unassigned https://github.com/llvm/llvm-project/pull/124477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-26 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: Unfortunately, I cannot forge a minimal example to reproduce this bug due to the aforementioned fact that `evalLocation` alters the state very rarely. A minimal example would be just execute an objective-c for loop like this: ``` for (T * element in collection) { } ``` Then

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-26 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 unassigned https://github.com/llvm/llvm-project/pull/124477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-26 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 unassigned https://github.com/llvm/llvm-project/pull/124477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-26 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 unassigned https://github.com/llvm/llvm-project/pull/124477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-26 Thread Ziqing Luo via cfe-commits
@@ -124,24 +124,26 @@ void ExprEngine::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S, bool isContainerNull = state->isNull(collectionV).isConstrainedTrue(); - ExplodedNodeSet dstLocation; - evalLocation(dstLocation, S, elem, Pred, state, elementV, false); ---

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-26 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/124477 In `VisitObjCForCollectionStmt`, the function does `evalLocation` for the current element at the original source state `Pred`. The evaluation may result in a new state, say `PredNew`. I.e., there is a tran

[clang] 131acb0 - [clang][NFC] Move static assert on StmtClass bounds from header to source

2024-12-20 Thread Ziqing Luo via cfe-commits
Author: Ziqing Luo Date: 2024-12-20T12:42:21-08:00 New Revision: 131acb07d814fabcc969dcaa63f4f352cd529267 URL: https://github.com/llvm/llvm-project/commit/131acb07d814fabcc969dcaa63f4f352cd529267 DIFF: https://github.com/llvm/llvm-project/commit/131acb07d814fabcc969dcaa63f4f352cd529267.diff LO

[clang] [clang][NFC] Fix the static assertion in 4797437 (PR #120643)

2024-12-20 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: > [#120341 > (comment)](https://github.com/llvm/llvm-project/pull/120341#discussion_r1893822845) oops, I saw this after I hit the merge button. I will do it in a follow-up commit. https://github.com/llvm/llvm-project/pull/120643 ___

[clang] [clang][NFC] Fix the static assertion in 4797437 (PR #120643)

2024-12-20 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 closed https://github.com/llvm/llvm-project/pull/120643 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][NFC] Fix the static assertion in 4797437 (PR #120643)

2024-12-19 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/120643 >From ada689aff13ea5c582280ce72d3e735ca07caf60 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 19 Dec 2024 13:44:42 -0800 Subject: [PATCH] [clang][NFC] Fix the static assertion in 4797437 In the previ

[clang] [clang][NFC] Fix the static assertion in 4797437 (PR #120643)

2024-12-19 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/120643 >From d1b45d14157f9adf4ec8f41840f269b262ee8da6 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 19 Dec 2024 13:44:42 -0800 Subject: [PATCH] [clang][NFC] Fix the static assertion in 4797437 In the previ

[clang] [clang][NFC] Fix the static assertion in 4797437 (PR #120643)

2024-12-19 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/120643 >From dd71be83e763128ce432d3a77e17abb439575f4d Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 19 Dec 2024 13:44:42 -0800 Subject: [PATCH] [clang][NFC] Fix the static assertion in 4797437 In the previ

[clang] [clang][NFC] Fix the static assertion in 4797437 (PR #120643)

2024-12-19 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/120643 >From b057ae37da2426e4ad04297600ce9bdf7d9a31c4 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 19 Dec 2024 13:44:42 -0800 Subject: [PATCH] [clang][NFC] Fix the static assertion in 4797437 In the previ

[clang] [clang][NFC] Fix the static assertion in 4797437 (PR #120643)

2024-12-19 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/120643 In the previous commit 4797437463e63ee289a1ff1904cfb7b2fe6cb4c2, I used `llvm::isInt(StmtClass::LAST##Class)` to test if `StmtClass` is strictly bounded by the an unsigned integer of 'NumStmtBits'. That i

[clang] [clang][NFC] Increase NumStmtBits by 2 as we are approaching the limit (PR #120341)

2024-12-19 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 closed https://github.com/llvm/llvm-project/pull/120341 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Wunsafe-buffer-usage] Fix false positive when const sized array is indexed by const evaluatable expressions (PR #119340)

2024-12-18 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 approved this pull request. LGTM, thank you @malavikasamak https://github.com/llvm/llvm-project/pull/119340 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-com

[clang] [clang][NFC] Increase NumStmtBits by 2 as we are approaching the limit (PR #120341)

2024-12-18 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: > Let's just increase to 9 bits. > > Have you checked whether the size of `Stmt` or `Expr` changes when you do > this? I changed it to 9 bits and checked that `Stmt` is still 8 bytes and `Expr` is still 16 bytes. https://github.com/llvm/llvm-project/pull/120341 __

[clang] [clang][NFC] Increase NumStmtBits by 2 as we are approaching the limit (PR #120341)

2024-12-18 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/120341 >From 69477100ca48508517a56c9efc3db6840bea82cb Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Wed, 18 Dec 2024 12:14:05 -0800 Subject: [PATCH] [clang][NFC] Increase NumStmtBits by 1 as we are approaching

[clang] [clang][NFC] Increase NumStmtBits by 2 as we are approaching the limit (PR #120341)

2024-12-17 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 edited https://github.com/llvm/llvm-project/pull/120341 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Increase NumStmtBits by 2 as we are approaching the limit (PR #120341)

2024-12-17 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/120341 We have already hit the limit of NumStmtBits downstream after 010d0115fc8e3834fc6f747f0841f3b1e467c4da, which adds 4 new StmtNodes. >From 6cb8ccb8005342c74018508e7e4d267bd6f44e4c Mon Sep 17 00:00:00 2001 F

[clang] [-Wunsafe-buffer-usage] Suppress warning for multi-dimensional constant arrays (PR #118249)

2024-12-09 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 approved this pull request. LGTM! Thanks. https://github.com/llvm/llvm-project/pull/118249 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [-Wunsafe-buffer-usage] Suppress warning for multi-dimensional constant arrays (PR #118249)

2024-12-06 Thread Ziqing Luo via cfe-commits
@@ -433,37 +433,36 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) { //already duplicated // - call both from Sema and from here - const auto *BaseDRE = - dyn_cast(Node.getBase()->IgnoreParenImpCasts()); - const auto *SLiteral = - dyn_cast(Node.ge

[clang] [ASTMatchers] AST matcher support for ObjC pointers (PR #117021)

2024-11-20 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 approved this pull request. Neat! https://github.com/llvm/llvm-project/pull/117021 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [-Wunsafe-buffer-usage] Fix bug in unsafe casts to incomplete types (PR #116433)

2024-11-18 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 closed https://github.com/llvm/llvm-project/pull/116433 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [-Wunsafe-buffer-usage] Fix bug in unsafe casts to incomplete types (PR #116433)

2024-11-18 Thread Ziqing Luo via cfe-commits
@@ -2270,19 +2270,28 @@ class UnsafeBufferUsageReporter : public UnsafeBufferUsageHandler { MsgParam = 5; } else if (const auto *ECE = dyn_cast(Operation)) { QualType destType = ECE->getType(); +bool destTypeComplete = true; + if (!isa(de

[clang] [-Wunsafe-buffer-usage] Fix bug in unsafe casts to incomplete types (PR #116433)

2024-11-18 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/116433 >From 429dd67554681595390828c990050c85dcbb557b Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 14 Nov 2024 23:08:47 -0800 Subject: [PATCH] [-Wunsafe-buffer-usage] Fix bug in unsafe cast to incomplete

[clang] [-Wunsafe-buffer-usage] Fix bug in unsafe casts to incomplete types (PR #116433)

2024-11-15 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/116433 Fixed the crash coming from attempting to get size of incomplete types. Casting `span.data()` to a pointer-to-incomplete-type should be immediately considered unsafe. Solving issue #116286. >From 5aacab

[clang] Respect the [[clang::unsafe_buffer_usage]] attribute for field and constructor initializers (PR #91991)

2024-11-14 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: @ZequanWu Thanks for the bug-catching! I will look into it! https://github.com/llvm/llvm-project/pull/91991 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [-Wunsafe-buffer-usage] Fix false positives in warning againt 2-parameter std::span constructor (PR #115797)

2024-11-12 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 approved this pull request. Nice! nit: please add the pattern `std::span{std::addressor(...), 1}` to the comment: ``` // Given a two-param std::span construct call, matches iff the call has the // following forms: // 1. `std::span{new T[n], n}`, where `n` is a

[clang] [Wunsafe-buffer-usage] Fix false positives in handling string literals. (PR #115552)

2024-11-11 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 approved this pull request. LGTM! Thank you @malavikasamak https://github.com/llvm/llvm-project/pull/115552 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-com

  1   2   3   >