[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

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

2024-11-06 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/114894 >From bfcce44fe554ff4b0e274de68e1c460075b925de Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Mon, 4 Nov 2024 14:56:10 -0800 Subject: [PATCH] [-Wunsafe-buffer-usage] Add alloc_size attribute knowledge to

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

2024-11-06 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 edited 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] [WIP][-Wunsafe-buffer-usage] Add alloc_size knowledge to the 2-param span constructor warning (PR #114894)

2024-11-04 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/114894 We can take advantage of the attribute `alloc_size`. For example, ``` void * malloc(size_t size) __attribute__((alloc_size(1))); std::span{(char *)malloc(x), x}; // this is safe ``` rdar://136634730 >F

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

2024-10-29 Thread Ziqing Luo via cfe-commits
@@ -420,6 +420,118 @@ AST_MATCHER(CXXConstructExpr, isSafeSpanTwoParamConstruct) { return false; } +class MaxValueEval : public RecursiveASTVisitor { + + std::vector val; + ASTContext &Context; + llvm::APInt Max; + unsigned bit_width; + +public: + typedef RecursiveASTV

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

2024-10-29 Thread Ziqing Luo via cfe-commits
@@ -420,6 +420,118 @@ AST_MATCHER(CXXConstructExpr, isSafeSpanTwoParamConstruct) { return false; } +class MaxValueEval : public RecursiveASTVisitor { + + std::vector val; + ASTContext &Context; + llvm::APInt Max; + unsigned bit_width; + +public: + typedef RecursiveASTV

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

2024-10-29 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 approved this pull request. LGTM! Thank you @danakj for the continuous effort! https://github.com/llvm/llvm-project/pull/91991 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailm

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

2024-10-29 Thread Ziqing Luo via cfe-commits
@@ -3912,3 +3896,56 @@ void clang::checkUnsafeBufferUsage(const Decl *D, } } } + +void clang::checkUnsafeBufferUsage(const Decl *D, + UnsafeBufferUsageHandler &Handler, + bool EmitSuggestions) { +#ifndef

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

2024-10-29 Thread Ziqing Luo via cfe-commits
@@ -420,6 +420,118 @@ AST_MATCHER(CXXConstructExpr, isSafeSpanTwoParamConstruct) { return false; } +class MaxValueEval : public RecursiveASTVisitor { + + std::vector val; + ASTContext &Context; + llvm::APInt Max; + unsigned bit_width; + +public: + typedef RecursiveASTV

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

2024-10-29 Thread Ziqing Luo via cfe-commits
@@ -420,6 +420,118 @@ AST_MATCHER(CXXConstructExpr, isSafeSpanTwoParamConstruct) { return false; } +class MaxValueEval : public RecursiveASTVisitor { + + std::vector val; + ASTContext &Context; + llvm::APInt Max; + unsigned bit_width; + +public: + typedef RecursiveASTV

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

2024-10-29 Thread Ziqing Luo via cfe-commits
@@ -420,6 +420,118 @@ AST_MATCHER(CXXConstructExpr, isSafeSpanTwoParamConstruct) { return false; } +class MaxValueEval : public RecursiveASTVisitor { + + std::vector val; + ASTContext &Context; + llvm::APInt Max; + unsigned bit_width; + +public: + typedef RecursiveASTV

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

2024-10-25 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: Hi @danakj , we are really looking forward to this change! Will you finish it soon? Or I can pick it up and land it on behalf of you? https://github.com/llvm/llvm-project/pull/91991 ___ cfe-commits mailing list cfe-commits@list

[clang] [-Wunsafe-buffer-usage] Fix false negatives of missing 2-param span ctors in constructor initializers (PR #113226)

2024-10-23 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: > This overlaps with #91991 which should probably be landed in its entirety. > (It looks like it's about attributes but in fact it isn't. It's about finding > _all_ gadgets in all those new places.) I think that patch was almost ready > and it was a matter of considering my

[clang] [-Wunsafe-buffer-usage] Fix false negatives of missing 2-param span ctors in constructor initializers (PR #113226)

2024-10-21 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: Worth to mention that there could be "false positives" introduced to those std::span calls in C'tor initializers because the safe-pattern matching is syntactic only, which doesn't know there can be "call stacks" involved in those recursive cases. https://github.com/llvm/l

[clang] [-Wunsafe-buffer-usage] Fix false negatives of missing 2-param span ctors in constructor initializers (PR #113226)

2024-10-21 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/113226 >From e27fccf11bb750e32453be923f6925abd4cfda31 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Mon, 21 Oct 2024 14:12:12 -0700 Subject: [PATCH 1/2] [-Wunsafe-buffer-usage] Fix false negatives of missing 2-

[clang] [-Wunsafe-buffer-usage] Fix false negatives of missing 2-param span ctors in constructor initializers (PR #113226)

2024-10-21 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/113226 The analysis now searches for every descendant stmt of constructor initializers and recurses if the descendant is another constructor call. (rdar://137999201) >From e27fccf11bb750e32453be923f6925abd4cfda3

[clang] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files (PR #109496)

2024-09-22 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 closed https://github.com/llvm/llvm-project/pull/109496 ___ 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 and suppress libc warnings for C files (PR #109496)

2024-09-20 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/109496 >From e7f7f82b25eaae86623ac8f47731892b3b629d7d Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Fri, 20 Sep 2024 16:27:09 -0700 Subject: [PATCH 1/4] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warni

[clang] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files (PR #109496)

2024-09-20 Thread Ziqing Luo via cfe-commits
@@ -784,12 +786,12 @@ AST_MATCHER_P(CallExpr, hasUnsafePrintfStringArg, return false; // possibly some user-defined printf function ASTContext &Ctx = Finder->getASTContext(); - QualType FristParmTy = FD->getParamDecl(0)->getType(); + QualType FirstParmTy = FD->getParam

[clang] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files (PR #109496)

2024-09-20 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/109496 >From e7f7f82b25eaae86623ac8f47731892b3b629d7d Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Fri, 20 Sep 2024 16:27:09 -0700 Subject: [PATCH 1/3] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warni

[clang] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files (PR #109496)

2024-09-20 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/109496 >From e7f7f82b25eaae86623ac8f47731892b3b629d7d Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Fri, 20 Sep 2024 16:27:09 -0700 Subject: [PATCH 1/2] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warni

[clang] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files (PR #109496)

2024-09-20 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/109496 >From e7f7f82b25eaae86623ac8f47731892b3b629d7d Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Fri, 20 Sep 2024 16:27:09 -0700 Subject: [PATCH] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings

[clang] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files (PR #109496)

2024-09-20 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/109496 - Fix a bug in UnsafeBufferUsage.cpp related to casting to PointerType (report by @hnrklssn [here](https://github.com/llvm/llvm-project/pull/101583#discussion_r1767705992)) - Suppress -Wunsafe-buffer-usage

[clang] [-Wunsafe-buffer-usage] Reduce false positives with constant arrays in libc warnings (PR #108308)

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

[clang] [-Wunsafe-buffer-usage] Reduce false positives with constant arrays in libc warnings (PR #108308)

2024-09-11 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/108308 >From 3c8830a0e69922faf4fad190ba0b2e01a3392e62 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Tue, 6 Aug 2024 17:54:23 -0700 Subject: [PATCH 1/2] [-Wunsafe-buffer-usage] Reduce false positives with consta

[clang] [-Wunsafe-buffer-usage] Reduce false positives with constant arrays in libc warnings (PR #108308)

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

[clang] [-Wunsafe-buffer-usage] Reduce false positives with constant arrays in libc warnings (PR #108308)

2024-09-11 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/108308 For `snprintf(a, sizeof a, ...)`, the first two arguments form a safe pattern if `a` is a constant array. In such a case, this commit will suppress the warning. (rdar://117182250) This pattern will effe

[clang] [WIP][-Wunsafe-buffer-usage] Add a new option for unsafe buffer warnings on libc functions (PR #105383)

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

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-09-06 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: > Btw a question about the new warning: So with > -Wunsafe-buffer-usage-in-libc-call clang now warns on the following? > > ``` > #include > > void foo(void) { > char q[10]; > snprintf(q, 10, "%s", "hello"); > } > ``` > > It says > > ``` > foo.c:5:3: warning: function

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-09-06 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: > > We're seeing a crash with this patch when compiling with -Weverything. > > ``` > > clang: ../../clang/include/clang/AST/Expr.h:3026: const clang::Expr > > *clang::CallExpr::getArg(unsigned int) const: Assertion `Arg < getNumArgs() > > && "Arg access out of range!"' faile

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-09-05 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: > There needs to be a flag to opt out of this to not break everybody who is > currently using unsafe-buffer-usage. #105383 seems to do that, but it really > should be in this same PR. Can this be reverted and relanded with the flag? @aeubanks you should be able to suppress

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-09-04 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: > There needs to be a flag to opt out of this to not break everybody who is > currently using unsafe-buffer-usage. #105383 seems to do that, but it really > should be in this same PR. Can this be reverted and relanded with the flag? ok, will do https://github.com/llvm/llvm

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

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

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

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

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-28 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/101583 >From cce5781733a7c294f10dc75f48372ff6ee331239 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 1 Aug 2024 16:36:27 -0700 Subject: [PATCH 1/5] [-Wunsafe-buffer-usage] Add warn on unsafe calls to libc f

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

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

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-28 Thread Ziqing Luo via cfe-commits
@@ -12383,6 +12383,13 @@ def warn_unsafe_buffer_operation : Warning< "%select{unsafe pointer operation|unsafe pointer arithmetic|" "unsafe buffer access|function introduces unsafe buffer manipulation|unsafe invocation of span::data}0">, InGroup, DefaultIgnore; +def warn_

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-28 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: Addressed comments. https://github.com/llvm/llvm-project/pull/101583 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-28 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/101583 >From cce5781733a7c294f10dc75f48372ff6ee331239 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 1 Aug 2024 16:36:27 -0700 Subject: [PATCH 1/4] [-Wunsafe-buffer-usage] Add warn on unsafe calls to libc f

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-28 Thread Ziqing Luo via cfe-commits
@@ -0,0 +1,101 @@ +// RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage \ +// RUN:-verify %s + +typedef struct {} FILE; +void memcpy(); +void __asan_memcpy(); +void strcpy(); +void strcpy_s(); +void wcscpy_s(); +unsigned strlen( const char* str ); +int fprintf(

[clang] [WIP][-Wunsafe-buffer-usage] Add a new option for unsafe buffer warnings on libc functions (PR #105383)

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

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-28 Thread Ziqing Luo via cfe-commits
@@ -12383,6 +12383,13 @@ def warn_unsafe_buffer_operation : Warning< "%select{unsafe pointer operation|unsafe pointer arithmetic|" "unsafe buffer access|function introduces unsafe buffer manipulation|unsafe invocation of span::data}0">, InGroup, DefaultIgnore; +def warn_

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-28 Thread Ziqing Luo via cfe-commits
@@ -443,6 +449,396 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) { return false; } +AST_MATCHER_P(CallExpr, hasNumArgs, unsigned, Num) { + return Node.getNumArgs() == Num; +} + +namespace libc_func_matchers { +// Under `libc_func_matchers`, define a set of matche

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-28 Thread Ziqing Luo via cfe-commits
@@ -1025,6 +1421,92 @@ class DataInvocationGadget : public WarningGadget { DeclUseList getClaimedVarUseSites() const override { return {}; } }; +class UnsafeLibcFunctionCallGadget : public WarningGadget { + const CallExpr *const Call; + constexpr static const char *const T

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-21 Thread Ziqing Luo via cfe-commits
@@ -0,0 +1,101 @@ +// RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage \ +// RUN:-verify %s + +typedef struct {} FILE; +void memcpy(); +void __asan_memcpy(); +void strcpy(); +void strcpy_s(); +void wcscpy_s(); +unsigned strlen( const char* str ); +int fprintf(

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-21 Thread Ziqing Luo via cfe-commits
@@ -0,0 +1,101 @@ +// RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage \ +// RUN:-verify %s + +typedef struct {} FILE; +void memcpy(); +void __asan_memcpy(); +void strcpy(); +void strcpy_s(); +void wcscpy_s(); +unsigned strlen( const char* str ); +int fprintf(

[clang] [Don't Merge][-Wunsafe-buffer-usage] Add a new option for unsafe buffer warnings on libc functions (PR #105383)

2024-08-20 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/105383 Depending on https://github.com/llvm/llvm-project/pull/101583 (rdar://117182250) >From b0970a849a21180315ace77e40f3db95fddac346 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 1 Aug 2024 16:36:27 -07

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-15 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/101583 >From cce5781733a7c294f10dc75f48372ff6ee331239 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 1 Aug 2024 16:36:27 -0700 Subject: [PATCH 1/3] [-Wunsafe-buffer-usage] Add warn on unsafe calls to libc f

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-15 Thread Ziqing Luo via cfe-commits
@@ -443,6 +448,368 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) { return false; } +namespace libc_fun_disjoint_inner_matchers { +// `libc_fun_disjoint_inner_matchers` covers a set of matchers that match +// disjoint node sets. They all take a `CoreName`, which

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-15 Thread Ziqing Luo via cfe-commits
@@ -443,6 +448,368 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) { return false; } +namespace libc_fun_disjoint_inner_matchers { +// `libc_fun_disjoint_inner_matchers` covers a set of matchers that match +// disjoint node sets. They all take a `CoreName`, which

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-15 Thread Ziqing Luo via cfe-commits
@@ -443,6 +448,368 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) { return false; } +namespace libc_fun_disjoint_inner_matchers { +// `libc_fun_disjoint_inner_matchers` covers a set of matchers that match +// disjoint node sets. They all take a `CoreName`, which

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-15 Thread Ziqing Luo via cfe-commits
@@ -483,6 +483,34 @@ bool clang::analyze_format_string::ParseFormatStringHasSArg(const char *I, return false; } +unsigned clang::analyze_format_string::ParseFormatStringFirstSArgIndex( +const char *&I, const char *E, unsigned ArgIndex, const LangOptions &LO, +const

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-15 Thread Ziqing Luo via cfe-commits
@@ -783,6 +783,18 @@ bool ParsePrintfString(FormatStringHandler &H, bool ParseFormatStringHasSArg(const char *beg, const char *end, const LangOptions &LO, const TargetInfo &Target); +/// Parse C format string and return index (relative to `ArgInde

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-15 Thread Ziqing Luo via cfe-commits
@@ -443,6 +448,368 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) { return false; } +namespace libc_fun_disjoint_inner_matchers { +// `libc_fun_disjoint_inner_matchers` covers a set of matchers that match +// disjoint node sets. They all take a `CoreName`, which

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-15 Thread Ziqing Luo via cfe-commits
@@ -2292,6 +2292,18 @@ class UnsafeBufferUsageReporter : public UnsafeBufferUsageHandler { } } + void handleUnsafeLibcCall(const CallExpr *Call, unsigned PrintfInfo, +ASTContext &Ctx) override { +// We have checked that there is a direct

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-15 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/101583 >From cce5781733a7c294f10dc75f48372ff6ee331239 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 1 Aug 2024 16:36:27 -0700 Subject: [PATCH 1/3] [-Wunsafe-buffer-usage] Add warn on unsafe calls to libc f

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-15 Thread Ziqing Luo via cfe-commits
@@ -443,6 +448,368 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) { return false; } +namespace libc_fun_disjoint_inner_matchers { +// `libc_fun_disjoint_inner_matchers` covers a set of matchers that match +// disjoint node sets. They all take a `CoreName`, which

[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)

2024-08-15 Thread Ziqing Luo via cfe-commits
@@ -443,6 +448,368 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) { return false; } +namespace libc_fun_disjoint_inner_matchers { +// `libc_fun_disjoint_inner_matchers` covers a set of matchers that match +// disjoint node sets. They all take a `CoreName`, which

[clang] [-Wunsafe-buffer-usage] Fix a small bug recently found (PR #102953)

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

[clang] [Safe Buffers] Fix a small bug recently found (PR #102953)

2024-08-13 Thread Ziqing Luo via cfe-commits
@@ -404,7 +404,7 @@ AST_MATCHER(CXXConstructExpr, isSafeSpanTwoParamConstruct) { if (Arg0Ty->isConstantArrayType()) { const APSInt ConstArrSize = -APSInt(cast(Arg0Ty)->getSize()); +APSInt(cast(Arg0Ty.getCanonicalType())->getSize()); ziqin

[clang] [Safe Buffers] Fix a small bug recently found (PR #102953)

2024-08-13 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/102953 >From d6c860de3facc37f27b17a26a01e48bc02b4659b Mon Sep 17 00:00:00 2001 From: ziqingluo-90 Date: Mon, 12 Aug 2024 11:57:17 -0700 Subject: [PATCH] [-Wunsafe-buffer-usage] Fix a bug in the ASTMatcher for span

[clang] Warning Libc functions (PR #101583)

2024-08-12 Thread Ziqing Luo via cfe-commits
@@ -443,6 +447,314 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) { return false; } +AST_MATCHER(CallExpr, isUnsafeLibcFunctionCall) { + static const std::set PredefinedNames{ + // numeric conversion: + "atof", + "atoi", + "atol", + "atoll

[clang] Warning Libc functions (PR #101583)

2024-08-12 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/101583 >From cce5781733a7c294f10dc75f48372ff6ee331239 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 1 Aug 2024 16:36:27 -0700 Subject: [PATCH 1/2] [-Wunsafe-buffer-usage] Add warn on unsafe calls to libc f

[clang] Warning Libc functions (PR #101583)

2024-08-12 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/101583 >From cce5781733a7c294f10dc75f48372ff6ee331239 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 1 Aug 2024 16:36:27 -0700 Subject: [PATCH 1/2] [-Wunsafe-buffer-usage] Add warn on unsafe calls to libc f

[clang] [Safe Buffers] Fix a small bug recently found (PR #102953)

2024-08-12 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/102953 `QualType::isConstantArrayType()` checks canonical type. So a following cast should be applied to canonical type as well: ``` if (Ty->isConstantArrayType()) cast(Ty.getCanonicalType()); // cast(Ty) is

[clang] Warning Libc functions (PR #101583)

2024-08-05 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/101583 >From 979619ea3ac0b52944468160f582d82fce3cee7d Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 1 Aug 2024 16:36:27 -0700 Subject: [PATCH] [-Wunsafe-buffer-usage] Add warn on unsafe calls to libc funct

[clang] Warning Libc functions (PR #101583)

2024-08-05 Thread Ziqing Luo via cfe-commits
@@ -443,6 +448,260 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) { return false; } +AST_MATCHER(CallExpr, isUnsafeLibcFunctionCall) { + static const std::set PredefinedNames{ + // numeric conversion: + "atof", + "atoi", + "atol", + "atoll

[clang] Warning Libc functions (PR #101583)

2024-08-03 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/101583 >From 8a8b317c2b1c73117bcbbf771a783338448724a5 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 1 Aug 2024 16:36:27 -0700 Subject: [PATCH 1/2] [-Wunsafe-buffer-usage] Add warn on unsafe calls to libc f

[clang] Warning Libc functions (PR #101583)

2024-08-03 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/101583 >From 8a8b317c2b1c73117bcbbf771a783338448724a5 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 1 Aug 2024 16:36:27 -0700 Subject: [PATCH] [-Wunsafe-buffer-usage] Add warn on unsafe calls to libc funct

[clang] Warning Libc functions (PR #101583)

2024-08-02 Thread Ziqing Luo via cfe-commits
ziqingluo-90 wrote: Though we probably don't need this warning anymore but this is really a great catch of wording issues! https://github.com/llvm/llvm-project/pull/101583 ___ cfe-commits mailing list cfe-commits@lis

[clang] Warning Libc functions (PR #101583)

2024-08-01 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/101583 >From 0ccb5a8fc0855b2dfb948c4bb844e0394b5cedb0 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 1 Aug 2024 16:36:27 -0700 Subject: [PATCH 1/3] [-Wunsafe-buffer-usage] Add warn on unsafe calls to libc f

[clang] Warning Libc functions (PR #101583)

2024-08-01 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/101583 >From 0ccb5a8fc0855b2dfb948c4bb844e0394b5cedb0 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 1 Aug 2024 16:36:27 -0700 Subject: [PATCH 1/2] [-Wunsafe-buffer-usage] Add warn on unsafe calls to libc f

[clang] Warning Libc functions (PR #101583)

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

[clang] Warning Libc functions (PR #101583)

2024-08-01 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/101583 None >From 0ccb5a8fc0855b2dfb948c4bb844e0394b5cedb0 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 1 Aug 2024 16:36:27 -0700 Subject: [PATCH 1/2] [-Wunsafe-buffer-usage] Add warn on unsafe calls to l

[clang] [Safe Buffers] Serialize unsafe_buffer_usage pragmas (PR #92031)

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

[clang] [Safe Buffers] Serialize unsafe_buffer_usage pragmas (PR #92031)

2024-06-13 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/92031 >From ac5aeb5c3a134d085320fc7fc5cf3f2c8c41a1f1 Mon Sep 17 00:00:00 2001 From: ziqingluo-90 Date: Mon, 13 May 2024 13:31:21 -0700 Subject: [PATCH 1/7] fix safe buffer opt-out region serialization --- clang/

[clang] [Safe Buffers] Serialize unsafe_buffer_usage pragmas (PR #92031)

2024-06-13 Thread Ziqing Luo via cfe-commits
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/92031 >From ac5aeb5c3a134d085320fc7fc5cf3f2c8c41a1f1 Mon Sep 17 00:00:00 2001 From: ziqingluo-90 Date: Mon, 13 May 2024 13:31:21 -0700 Subject: [PATCH 1/6] fix safe buffer opt-out region serialization --- clang/

  1   2   >