[clang] [C++26][clang] Implement P2795R5 'Erroneous behaviour for uninitialized reads' (PR #177614)
Sirui Mu via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 12 05:42:46 PST 2026
================
@@ -0,0 +1,82 @@
+// RUN: %clang_cc1 -std=c++26 -triple x86_64-unknown-unknown %s -emit-llvm -o - | FileCheck %s -check-prefix=CXX26
+// RUN: %clang_cc1 -std=c++26 -triple x86_64-unknown-unknown -ftrivial-auto-var-init=zero %s -emit-llvm -o - | FileCheck %s -check-prefix=ZERO
+// RUN: %clang_cc1 -std=c++26 -triple x86_64-unknown-unknown -ftrivial-auto-var-init=pattern %s -emit-llvm -o - | FileCheck %s -check-prefix=PATTERN
+
+// Test for C++26 [[indeterminate]] attribute (P2795R5)
+// The [[indeterminate]] attribute opts out of erroneous initialization.
+
+template<typename T> void used(T &) noexcept;
+
+extern "C" {
+
+// Test: [[indeterminate]] should suppress zero/pattern initialization
+// CXX26-LABEL: test_indeterminate_local_var(
+// CXX26: alloca i32
+// CXX26-NOT: store
+// CXX26: call void
+// ZERO-LABEL: test_indeterminate_local_var(
+// ZERO: alloca i32
+// ZERO-NOT: store
+// ZERO: call void
+// PATTERN-LABEL: test_indeterminate_local_var(
+// PATTERN: alloca i32
+// PATTERN-NOT: store
+// PATTERN: call void
+void test_indeterminate_local_var() {
+ [[indeterminate]] int x;
+ used(x);
+}
+
+// Test: Without [[indeterminate]], zero/pattern init should apply
+// CXX26-LABEL: test_normal_local_var(
+// CXX26: alloca i32
+// CXX26-NEXT: call void
----------------
Lancern wrote:
I believe erroneous values could not be modeled as LLVM `undef` values. Maybe we should fill the uninitialized alloca with a fixed value.
https://github.com/llvm/llvm-project/pull/177614
More information about the cfe-commits
mailing list