This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Implement IntegralToPointer casts
AbandonedPublic

Authored by tbaeder on Nov 9 2022, 4:59 AM.

Details

Summary

The pointers created through such a cast are not usable in a constant expression as far as I know, but we need to be able to express them. Do that via a Pointer with a nullptr pointee and an Offset that is the given integer.

Diff Detail

Event Timeline

tbaeder created this revision.Nov 9 2022, 4:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 9 2022, 4:59 AM
Herald added a subscriber: inglorion. · View Herald Transcript
tbaeder requested review of this revision.Nov 9 2022, 4:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 9 2022, 4:59 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tbaeder added inline comments.Nov 9 2022, 5:02 AM
clang/lib/AST/Interp/ByteCodeExprGen.cpp
189–193

This is a tiny hack to get the C test working.

tbaeder updated this revision to Diff 474459.Nov 10 2022, 12:15 AM
tbaeder updated this revision to Diff 474929.Nov 12 2022, 1:11 AM
tbaeder updated this revision to Diff 474930.

I'd expect more test coverage for these changes. Like a C-style cast and a reinterpret_cast in C++ code

shafik added a comment.Dec 1 2022, 7:52 PM

I agree with @aaron.ballman I expect some more tests for this.

clang/lib/AST/Interp/Pointer.h
70

Is the only cast we have a Pointer that is a nullptr but has an Offset is from a integral to pointer cast?

Note that according to https://clang.llvm.org/docs/ConstantInterpreter.html#pointers, such pointers had their own pointer type (TargetPointer), so I'm not sure if the approach here is the right one.

tbaeder abandoned this revision.May 15 2023, 8:01 AM

I've already abandoned this locally, pretty sure I'll end up taking another approach.