Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Exempt consteval from -Wunsafe-buffer-usage?

49 views
Skip to first unread message

Erik Jensen

unread,
Feb 25, 2025, 10:29:52 PMFeb 25
to Chromium-dev
I have a consteval function that verifies at compile time that the passed const char * is a valid, null-terminated string matching a specific format.  The reason the pointer arithmetic in the logic is safe is because it can only be evaluated at compile time, where reading past the end of an improperly terminated string will result in a compiler error, not an invalid memory access.

I can wrap the offending pointer arithmetic with UNSAFE_BUFFERS(), but that would mean that the code would still compile if consteval were changed to constexpr in the future.

Would it make sense for the unsafe-buffers plugin to suppress diagnostics inside of consteval functions?

Joe Mason

unread,
Feb 26, 2025, 12:16:06 PMFeb 26
to rkj...@chromium.org, Chromium-dev
How about adding a CONSTEVAL_UNSAFE_BUFFERS macro that contains the same pragma as UNSAFE_BUFFERS, plus a static assert that only compiles in consteval context?

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAN%3DK5G-STgWfAr7rMHmk4F6%2BeKx9yq7b61BJKXVY6E6N7SHmZg%40mail.gmail.com.

Peter Kasting

unread,
Feb 26, 2025, 12:20:46 PMFeb 26
to rkj...@chromium.org, Chromium-dev
Ideally we would never warn on code not executed at runtime. This reminds me of https://github.com/llvm/llvm-project/issues/92665.

PK

Tom Sepez

unread,
Feb 27, 2025, 1:05:24 PMFeb 27
to pkas...@chromium.org, rkj...@chromium.org, Chromium-dev
Gah, send my response from the wrong account and it bounced off the mailing iist. Anyways, a few days ago I said:
Seems reasonable to me. Let me see if there is a bug in LLVM's tracker for something like this. In the meantime wrapping will be the workaround.


--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
Reply all
Reply to author
Forward
0 new messages