[PATCH] D131942: [clang][Inter[ Implement bool and nullptr literal expressions

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 17 07:50:08 PDT 2022


tbaeder added inline comments.


================
Comment at: clang/lib/AST/Interp/Disasm.cpp:26
 inline std::enable_if_t<!std::is_pointer<T>::value, T> ReadArg(Program &P,
-                                                               CodePtr OpPC) {
+                                                               CodePtr &OpPC) {
   return OpPC.read<T>();
----------------
erichkeane wrote:
> Are you sure this isn't intentional that this is passed by value?  With a name like CodePtr, it certainly SOUNDS like it means to be passed by value.
`CodePtr::read()` advances the pointer that `CodePtr` wraps , so copying just to call `read()` on it makes little sense. E.g. in https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/Interp/Interp.cpp#L401-L412, `ReadArg` must advance the `CodePtr`, otherwise two consecutive `ReadArg` calls will read the same thing.


================
Comment at: clang/lib/AST/Interp/Function.h:69
   /// Returns a pointer to the start of the code.
-  CodePtr getCodeBegin() const;
+  CodePtr getCodeBegin() const { return Code.data(); }
   /// Returns a pointer to the end of the code.
----------------
erichkeane wrote:
> is this an unrelated NFC change?  In the future, please keep this out of patches that do stuff.
Okay.


================
Comment at: clang/test/AST/Interp/literals.cpp:14
+constexpr bool getTrue() { return true; }
+constexpr bool getFalse() { return false; }
----------------
erichkeane wrote:
> can you also do a 'getNullptr'?  Also, a static-assert for all 3 of the functions as well.
I can do a `getNull()`, but I can't call any of the functions yet, function calls aren't implemented yet.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131942/new/

https://reviews.llvm.org/D131942



More information about the cfe-commits mailing list