[PATCH] D132829: [clang][Interp] Handle ImplictValueInitExprs

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 31 03:16:41 PDT 2022


tbaeder updated this revision to Diff 456915.

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

https://reviews.llvm.org/D132829

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/arrays.cpp


Index: clang/test/AST/Interp/arrays.cpp
===================================================================
--- /dev/null
+++ clang/test/AST/Interp/arrays.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+
+/// expected-no-diagnostics
+/// ref-no-diagnostics
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wc99-extensions"
+#pragma clang diagnostic ignored "-Winitializer-overrides"
+/// FIXME: The example below tests ImplicitValueInitExprs, but we can't
+///   currently evaluate other parts of it.
+#if 0
+struct fred {
+  char s [6];
+  int n;
+};
+
+struct fred y [] = { [0] = { .s[0] = 'q' } };
+#endif
+#pragma clang diagnostic pop
Index: clang/lib/AST/Interp/Opcodes.td
===================================================================
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -203,6 +203,7 @@
 // [] -> [Integer]
 def Zero : Opcode {
   let Types = [AluTypeClass];
+  let HasGroup = 1;
 }
 
 // [] -> [Pointer]
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -75,6 +75,7 @@
   bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E);
   bool VisitUnaryOperator(const UnaryOperator *E);
   bool VisitDeclRefExpr(const DeclRefExpr *E);
+  bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -223,6 +223,14 @@
   return this->bail(BO);
 }
 
+template <class Emitter>
+bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E) {
+  if (Optional<PrimType> T = classify(E))
+    return this->emitZero(*T, E);
+
+  return false;
+}
+
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::discard(const Expr *E) {
   OptionScope<Emitter> Scope(this, /*NewDiscardResult=*/true);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132829.456915.patch
Type: text/x-patch
Size: 2195 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220831/0e418e7d/attachment-0001.bin>


More information about the cfe-commits mailing list