[clang] 38018ec - [clang][Interp][NFC] Add a failing test case for ArrayInitLoopExprs

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 28 22:04:43 PDT 2023


Author: Timm Bäder
Date: 2023-09-29T07:04:31+02:00
New Revision: 38018ecf965fda81d15edfb904b5b28adb6051b0

URL: https://github.com/llvm/llvm-project/commit/38018ecf965fda81d15edfb904b5b28adb6051b0
DIFF: https://github.com/llvm/llvm-project/commit/38018ecf965fda81d15edfb904b5b28adb6051b0.diff

LOG: [clang][Interp][NFC] Add a failing test case for ArrayInitLoopExprs

Added: 
    

Modified: 
    clang/test/AST/Interp/arrays.cpp

Removed: 
    


################################################################################
diff  --git a/clang/test/AST/Interp/arrays.cpp b/clang/test/AST/Interp/arrays.cpp
index 22ccafd579241b6..5640f57f6aeb826 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
-// RUN: %clang_cc1 -verify=ref %s
+// RUN: %clang_cc1 -verify=ref -DCUR_INTERP %s
 
 constexpr int m = 3;
 constexpr const int *foo[][5] = {
@@ -350,3 +350,24 @@ namespace ZeroInit {
   static_assert(b.f[0] == 0.0, "");
   static_assert(b.f[1] == 0.0, "");
 }
+
+namespace ArrayInitLoop {
+  /// FIXME: The ArrayInitLoop for the decomposition initializer in g() has
+  /// f(n) as its CommonExpr. We need to evaluate that exactly once and not
+  /// N times as we do right now.
+#ifndef CUR_INTERP
+  struct X {
+      int arr[3];
+  };
+  constexpr X f(int &r) {
+      return {++r, ++r, ++r};
+  }
+  constexpr int g() {
+      int n = 0;
+      auto [a, b, c] = f(n).arr;
+      return a + b + c;
+  }
+  static_assert(g() == 6); // expected-error {{failed}} \
+                           // expected-note {{15 == 6}}
+#endif
+}


        


More information about the cfe-commits mailing list