[clang] [clang][bytecode] Emit diagnostics from GetGlobalUnchecked (PR #137203)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 24 08:48:07 PDT 2025
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/137203
If the global is uninitialized.
>From 87377cd713004492ca9c989e1e7de806ba972ebf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Thu, 24 Apr 2025 17:46:49 +0200
Subject: [PATCH] [clang][bytecode] Emit diagnostics from GetGlobalUnchecked
If the global is uninitialized.
---
clang/lib/AST/ByteCode/Interp.h | 2 +-
clang/test/AST/ByteCode/cxx11.cpp | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 99b032bee9e3d..01c955b8548d3 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1433,7 +1433,7 @@ bool GetGlobal(InterpState &S, CodePtr OpPC, uint32_t I) {
template <PrimType Name, class T = typename PrimConv<Name>::T>
bool GetGlobalUnchecked(InterpState &S, CodePtr OpPC, uint32_t I) {
const Pointer &Ptr = S.P.getPtrGlobal(I);
- if (!Ptr.isInitialized())
+ if (!CheckInitialized(S, OpPC, Ptr, AK_Read))
return false;
S.Stk.push<T>(Ptr.deref<T>());
return true;
diff --git a/clang/test/AST/ByteCode/cxx11.cpp b/clang/test/AST/ByteCode/cxx11.cpp
index 004f704145afd..5daf6adf08cf5 100644
--- a/clang/test/AST/ByteCode/cxx11.cpp
+++ b/clang/test/AST/ByteCode/cxx11.cpp
@@ -194,3 +194,11 @@ namespace DynamicCast {
int g : (S*)(void*)(sptr) == sptr;
};
}
+
+namespace GlobalInitializer {
+ extern int &g; // both-note {{here}}
+ struct S {
+ int G : g; // both-error {{constant expression}} \
+ // both-note {{initializer of 'g' is unknown}}
+ };
+}
More information about the cfe-commits
mailing list