llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

If the global is uninitialized.

---
Full diff: https://github.com/llvm/llvm-project/pull/137203.diff


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Interp.h (+1-1) 
- (modified) clang/test/AST/ByteCode/cxx11.cpp (+8) 


``````````diff
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}}
+  };
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/137203
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to