[clang] [clang][bytecode] Implement __builtin_constant_p differently (PR #122099)

Nikolas Klauser via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 9 07:56:06 PST 2025


philnik777 wrote:

> > * We check whether two pointers are in the same range
> > 
> > Is that possible to implement in the interpreter without going back to AST visitors?
> 
> I take "in the same range" meaning as "can be compared at compile time at all" here, so yes, that would be rather trivial (we have to do the check already anyway of course).

Yes, that's the interesting question. Currently we assume that if `__builtin_constant_p(__begin <= __ptr && __ptr < __end)` is false, `__ptr` can't be within the the range `[__begin, __ptr)`.

> Note that of the two use cases you mentioned here, neither works with the code in this PR. :(

That's not great :(. We can of course use new builtins (which is probably a good idea anyway), but I don't know how long you support older libc++ versions usually. I think it should be possible to add support for these cases though, right? We're just doing comparisons or checking whether it's possible to read a variable.

https://github.com/llvm/llvm-project/pull/122099


More information about the cfe-commits mailing list