[PATCH] D137488: [clang][Interp] Array initialization via string literal

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 9 00:35:53 PST 2022


tbaeder added inline comments.


================
Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1133-1134
+  } else if (const auto *SL = dyn_cast<StringLiteral>(Initializer)) {
+    const ArrayType *AT = SL->getType()->getAsArrayTypeUnsafe();
+    const auto *CAT = cast<ConstantArrayType>(AT);
+    size_t NumElems = CAT->getSize().getZExtValue();
----------------
aaron.ballman wrote:
> 
I feel like every time I write the code to get the `ConstantArrayType` from some array expression, I use a different version. I've never used `getAsConstantArrayType()` before :)


================
Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1143
+    case 1:
+      CharType = PT_Sint8;
+      break;
----------------
aaron.ballman wrote:
> Should we be looking at the sign of `char` to decide whether to use a uint8 or an sint8?
I was wondering about that too, but this code is copy/paste from `Program.cpp` where we create global storage for string literals. That code works, so I assume it will work here, too. Getting rid of the duplication might be nice though.


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

https://reviews.llvm.org/D137488



More information about the cfe-commits mailing list