[PATCH] D149960: [clang][Interp] Fix ignoring String- and CharacterLiterals

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 5 07:55:16 PDT 2023


tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149960

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/literals.cpp


Index: clang/test/AST/Interp/literals.cpp
===================================================================
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -901,6 +901,8 @@
     (int[]){1,2,3};
     int arr[] = {1,2,3};
     arr[0];
+    "a";
+    'b';
 
     return 0;
   }
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -676,6 +676,8 @@
 
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitStringLiteral(const StringLiteral *E) {
+  if (DiscardResult)
+    return true;
   unsigned StringIndex = P.createGlobalString(E);
   return this->emitGetPtrGlobal(StringIndex, E);
 }
@@ -683,6 +685,8 @@
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitCharacterLiteral(
     const CharacterLiteral *E) {
+  if (DiscardResult)
+    return true;
   return this->emitConst(E->getValue(), E);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149960.519852.patch
Type: text/x-patch
Size: 1010 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230505/604df9db/attachment.bin>


More information about the cfe-commits mailing list