https://github.com/mxms0 created https://github.com/llvm/llvm-project/pull/171503
We dont need to visit or warn on consteval functions as they can't have UB. >From 6ca667130537476bd4268e15b0f899446f30b6e8 Mon Sep 17 00:00:00 2001 From: mxms <[email protected]> Date: Tue, 9 Dec 2025 20:54:14 +0000 Subject: [PATCH] [-Wunsafe-buffer-usage] Ignore consteval functions We dont need to visit or warn on consteval functions as they can't have UB. --- clang/lib/Analysis/UnsafeBufferUsage.cpp | 5 +++++ clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp index da155d31d4a88..893462e3bad58 100644 --- a/clang/lib/Analysis/UnsafeBufferUsage.cpp +++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp @@ -4458,6 +4458,11 @@ void clang::checkUnsafeBufferUsage(const Decl *D, SmallVector<Stmt *> Stmts; if (const auto *FD = dyn_cast<FunctionDecl>(D)) { + // Consteval functions are free of UB by the spec, so we don't need to + // visit them or produce diagnostics. + if (FD->isConsteval()) { + return; + } // We do not want to visit a Lambda expression defined inside a method // independently. Instead, it should be visited along with the outer method. // FIXME: do we want to do the same thing for `BlockDecl`s? diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp b/clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp index 41d38ada48788..6fad7585026f2 100644 --- a/clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp +++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp @@ -406,4 +406,11 @@ void testMultiLineDeclStmt(int * p) { foo(ap1[1]); // expected-note{{used in buffer access here}} } +#if __cplusplus >= 202002L +consteval void testConstevalPtrArithmetic(int idx) { + int y[3] = {0, 1, 2}; + foo(y[idx]); +} +#endif + #endif _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
