llvm / llvm/llvm-project

[Clang] __builtin_assume_dereferenceable should be constexpr

Open
#168,335 3 comments 0 reactions 0 assignees View on GitHub
clang:frontend constexpr
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Currently `__builtin_assume_dereferenceable` isn't constexpr. I don't think there is a fundamental problem with constant evaluating it though. It should be possible to check whether, from a certain pointer, there are indeed N bytes that can be dereferenced. The compiler has to do that anyways AFAICT, since out of bounds accesses need to be diagnosed during constant evaluation.

Contributor guide

Open the contributing guide

Research direction

Start by locating Clang's implementation and tests for __builtin_assume_dereferenceable, then trace how constant evaluation handles its pointer and byte-count arguments. Done means the builtin can be used in constexpr evaluation while still diagnosing out-of-bounds accesses during constant evaluation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.