https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/137211

>From 9388799f1a7bb4d6bbfc467db569aa61c4666445 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com>
Date: Thu, 24 Apr 2025 18:29:36 +0200
Subject: [PATCH] [clang][bytecode] Allow forming pointers to fields of extern
 globals

This should be fine as long as we're not reading from it.

Note that this regresses
CXX/special/class.init/class.inhctor.init/p1.cpp, which used to work
fine with the bytecode interpreter.

That's because this code now fails:

  struct Param;
  struct A {
    constexpr A(Param);
    int a;
  };

  struct B : A { B(); using A::A; int b = 2; };
  struct Wrap1 : B { constexpr Wrap1(); };
  struct Wrap2 : Wrap1 {};
  extern const Wrap2 b;

  struct Param {
    constexpr Param(int c) : n(4 * b.a + b.b + c) {}
    int n;
  };

and reports that the Param() constructor is never a valid constant
expression. But that's true and the current interpeter should
report that as well. It also fails when calling at compile time.
---
 clang/lib/AST/ByteCode/Interp.cpp | 2 --
 clang/test/AST/ByteCode/cxx11.cpp | 6 ++++++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index 6f277a7488836..23fd894bd6a3e 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1323,8 +1323,6 @@ static bool getField(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr,
       !CheckNull(S, OpPC, Ptr, CSK_Field))
     return false;
 
-  if (!CheckExtern(S, OpPC, Ptr))
-    return false;
   if (!CheckRange(S, OpPC, Ptr, CSK_Field))
     return false;
   if (!CheckArray(S, OpPC, Ptr))
diff --git a/clang/test/AST/ByteCode/cxx11.cpp 
b/clang/test/AST/ByteCode/cxx11.cpp
index 5daf6adf08cf5..cb05f26d11206 100644
--- a/clang/test/AST/ByteCode/cxx11.cpp
+++ b/clang/test/AST/ByteCode/cxx11.cpp
@@ -202,3 +202,9 @@ namespace GlobalInitializer {
                // both-note {{initializer of 'g' is unknown}}
   };
 }
+
+namespace ExternPointer {
+  struct S { int a; };
+  extern const S pu;
+  constexpr const int *pua = &pu.a; // Ok.
+}

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to