Skip to content

Commit 3b58a60

Browse files
authored
[clang][bytecode] Allow forming pointers to fields of extern globals (#137211)
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: ```c++ 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.
1 parent 6d99d1a commit 3b58a60

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,8 +1323,6 @@ static bool getField(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
13231323
!CheckNull(S, OpPC, Ptr, CSK_Field))
13241324
return false;
13251325

1326-
if (!CheckExtern(S, OpPC, Ptr))
1327-
return false;
13281326
if (!CheckRange(S, OpPC, Ptr, CSK_Field))
13291327
return false;
13301328
if (!CheckArray(S, OpPC, Ptr))

clang/test/AST/ByteCode/cxx11.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,9 @@ namespace GlobalInitializer {
202202
// both-note {{initializer of 'g' is unknown}}
203203
};
204204
}
205+
206+
namespace ExternPointer {
207+
struct S { int a; };
208+
extern const S pu;
209+
constexpr const int *pua = &pu.a; // Ok.
210+
}

0 commit comments

Comments
 (0)